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.
Value | Description |
---|---|
anchorname | anchor part of a URL |
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:
<!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>