Anchor hash property
Definition and usage
hash
Property setting or returning href attribute value of the anchor part.
The anchor part is the part after the hash (#) in the URL.
Note:Do not include the hash (#) when this property is used to set the anchor part.
See also:
JavaScript Reference Manual:location.hash property
Example
Example 1
Return the anchor part of the link:
var x = document.getElementById("myAnchor").hash;
Example 2
Change the anchor part of the link:
document.getElementById("myAnchor").hash = "newhashvalue";
Syntax
Return the hash property:
anchorObject.hash
Set hash property:
anchorObject.hash = anchorname
Attribute Value
Value | Description |
---|---|
anchorname | Specifies the anchor part of the URL. |
Technical Details
Return value: | A string value representing the anchor part of the URL, including the hash (#). |
---|
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |