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
has been supported in all browsers since HTML 4 (1997).
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 11 | Yes | Yes | Yes | Yes |
❮ Anchor Object
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.