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

Location hash Property

Location Object Reference Location Object

Example

Return the anchor part of a URL. Assume that the current URL is http://www.example.com/test.htm#part2:

var x = location.hash;

The result of x will be:

#part2

More "Try it Yourself" examples below.


Definition and Usage

The hash property sets or returns the anchor part of a URL, including 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:

location.hash

Set the hash property:

location.hash=anchorname

Property Values

Value Type Description
anchorname String Specifies the anchor part of a URL

Technical Details

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


Examples

More Examples

Example

Set the anchor part:

location.hash = "part5";

Try it yourself »


Location Object Reference Location Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook