Latest web development tutorials
 

Location hash Property

< 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