Anchor hash Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

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>
<html>
<body>

<p><a id="myAnchor" target="_blank" href="http://www.example.com/test.htm#part2">Example link</a></p>

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

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

<script>
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;
}
</script>

</body>
</html>

Related Tutorials