Anchor search Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

The search property sets or gets the querystring part of the href attribute value.

The querystring is after the question mark ?.

Property Values to Set

Value Description
querystring Sets the search part of a URL

Return Value

A String, representing the querystring part of the URL, including the question mark (?)

The following code shows how to Return the querystring part of a link:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

<button onclick="myFunction()">get the querystring part of the link above</button>

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

<script>
function myFunction() {//from w ww  .j a v a2  s  .co  m
    var v = document.getElementById("myAnchor").search;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials