Anchor hash Property
Example
Get the anchor part of a link:
let text = document.getElementById("myAnchor").hash;
Try it Yourself »
Change the anchor part of a link:
document.getElementById("myAnchor").hash = "newhashvalue";
Try it Yourself »
Description
The hash property sets or returns the anchor part of an href attribute.
The anchor part is the part of the URL after the hash sign (#).
Note
When hash is used to set the anchor part, do not include the hash sign (#).
See Also:
Syntax
Return the hash property:
anchorObject.hash
Set the hash property:
anchorObject.hash = anchorname
Parameters
Parameter | Description |
anchorname | The anchor part of a URL. |
Return Value
Type | Description |
String | The anchor part of a URL, including the hash sign (#). |
Browser Support
hash
is an HTML4 feature.
It has been supported in all browsers since 1997.
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 11 |
❮ Anchor Object