Window location.hash
Examples
Get the anchor part of the URL:
<a href="/js/js_strings.asp#part2">JavaScript Strings</a>
Try it Yourself »
Set the anchor part:
location.hash = "part5";
Try it Yourself »
Definition and Usage
The location.hash
property sets or returns the anchor part of a URL, including the hash
sign (#).
Note
When location.hash
is used to set the anchor part,
do not include the hash sign (#).
Syntax
Return the hash property:
location.hash
Set the hash property:
location.hash = anchorname
Parameters
Parameter | Description |
anchorname | The anchor part of a URL. |
Return Value
Type | Description |
A string | The anchor part of the URL, including the hash sign (#). |
Browser Support
location.hash
is supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |