Location hash Property - Javascript Browser Object Model

Javascript examples for Browser Object Model:Location


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

When setting the anchor part, do not include the hash sign (#).

Set the hash property with the following Values

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

Return Value

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

The following code shows how to Return the anchor part of a URL.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {/*  w w w.  j ava 2  s  . co m*/
    var v = location.hash;
    document.getElementById("demo").innerHTML = v;


Related Tutorials