Anchor hash Property - change the hash property value - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

Anchor hash Property - change the hash property value

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()">change the anchor part of the link above</button>

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

<script>
function myFunction() {//  w  w w.  j av a2  s.  c o  m
    document.getElementById("myAnchor").hash = "newhashvalue";
    document.getElementById("demo").innerHTML = "The anchor part was changed from '#part2' to '#newhashvalue'";
}
</script>

</body>
</html>

Related Tutorials