Window location.hash

Examples

Get the anchor part of the URL:

<a href="/js/js_strings.asp#part2">JavaScript Strings</a>
Try it Yourself »

Set the anchor part:

location.hash = "part5";
Try it Yourself »

Description

The location.hash property sets or returns the anchor part of a URL, including the hash sign (#).

Note

When location.hash is used to set the anchor part, do not include the hash sign (#).


Syntax

Return the hash property:

location.hash

Set the hash property:

location.hash = anchorname

Parameters

Parameter Description
anchorname The anchor part of a URL.

Return Value

Type Description
A stringThe anchor part of the URL, including the hash sign (#).

Browser Support

location.hash is supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.