Anchor hash Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor


The hash property sets or gets the anchor value (after the hash sign (#)) of the href attribute value.

Do not include the hash sign #, when setting hash property value.

Property Values

Value Description
anchorname anchor part of a URL

Return Value

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

The following code shows how to Return the anchor part of a link:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<p><a id="myAnchor" target="_blank" href="">Example link</a></p>

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

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

function myFunction() {//from   w  w  w.j a  v  a 2 s .co  m
    var x = document.getElementById("myAnchor").hash;
    document.getElementById("demo").innerHTML = x;


Related Tutorials