Javascript DOM HTML Anchor hash Property set

Introduction

Change the anchor part of a link:

document.getElementById("myAnchor").hash = "newhashvalue";

View in separate window

<!DOCTYPE html>
<html>
<body>
<p><a id="myAnchor" href="http://www.java2s.com/index.html#part2">Example link</a></p>
<p id="demo"></p>
<button onclick="myFunction()">Test</button>
<script>
function myFunction() {/* w  ww  .jav  a 2s.co  m*/
  document.getElementById("myAnchor").hash = "newhashvalue";
  document.getElementById("demo").innerHTML = "value changed";

}
</script>
</body>
</html>



PreviousNext

Related