Javascript DOM HTML Anchor search Property get

Introduction

The search property sets or gets the query string of the href attribute value.

The URL query string is after the question mark ?.

It sets URL parameters.

Return the query string part of a link:

var x = document.getElementById("myAnchor").search;

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<p><a id="myAnchor" href="http://www.java2s.com/index.htm?id=searchWord">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 .c  o m*/
  var x = document.getElementById("myAnchor").search;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related