Javascript DOM HTML Anchor search Property set

Introduction

Change the query string of a link:

document.getElementById("myAnchor").search = "somenewsearchvalue";

Click the button to change the query string part of the link.

View in separate window

<!DOCTYPE html>
<html>
<body>

<p><a id="myAnchor" 
      target="_blank" 
      href="http://www.java2s.com:80/test.htm?id=searchWord">Example link</a></p>

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

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

<script>
function myFunction() {//w w w .j a  v  a 2 s  . com
  document.getElementById("myAnchor").search = "newValue";
  document.getElementById("demo").innerHTML = "The query string was changed";
}
</script>
</body>
</html>



PreviousNext

Related