X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Anchor hash Property

Anchor Object Reference Anchor Object

Example

Return the anchor part of a link:

var x = document.getElementById("myAnchor").hash;

The result of x will be:

#part2

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

Internet Explorer Firefox Opera Google Chrome Safari

The hash property is supported in all major browsers.


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 Reference Anchor Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook