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


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

Internet Explorer Firefox Opera Google Chrome Safari

The hash property is supported in all major browsers.


Syntax

Return the hash property:

location.hash

Set the hash property:

location.hash=anchorname

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

Return Value

Type Description
String The anchor part of the URL, including the hash sign (#)


Examples

More Examples

Set the anchor part
How to set the anchor part of a URL.


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