THE WORLD'S LARGEST WEB DEVELOPER SITE

Anchor hash Property

❮ Anchor Object

Example

Return the anchor part of a link:

var x = document.getElementById("myAnchor").hash;
Try it Yourself »

Definition and Usage

The hash property sets or returns the anchor part of the href attribute value.

The anchor part is the part of the URL after the hash sign (#).

Note: When this property is used to set the anchor part, do not include the hash sign (#).


Browser Support

Property
hash Yes Yes Yes Yes Yes

Syntax

Return the hash property:

anchorObject.hash

Set the hash property:

anchorObject.hash = anchorname

Property Values

Value Description
anchorname Specifies the anchor part of a URL

Technical Details

Return Value: A String, representing the anchor part of a URL, including the hash sign (#)

More Examples

Example

Change the anchor part of a link:

document.getElementById("myAnchor").hash = "newhashvalue";
Try it Yourself »

Related Pages

JavaScript reference: location.hash Property


❮ Anchor Object