Anchor search Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor


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>

<p><a id="myAnchor" target="_blank" href="">Example link</a></p>

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

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

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


Related Tutorials