HTML DOM Anchor search Property
Last Updated :
29 Jan, 2024
The Anchor search Property in HTML DOM is used to set or return the querystring part of the href attribute. The querystring part is specified after the question mark(?) in the URL. It is often used for parameter passing.
Syntax:
Property Value: It contains single value querystring which is used to specify the search part of the URL.
Return Value: It returns a string value which represents the query string part of the URL also included the question mark (?).
Example 1: This examples returns the Anchor search Property.
html
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM Anchor search Property
</ title >
</ head >
< body style = "text-align: center;" >
< h1 >GeeksforGeeks</ h1 >
< h2 >HTML DOM Anchor search Property</ h2 >
< p >Welcome to
< a href =
id = "GFG" target = "_self" >
GeeksforGeeks
</ a >
</ p >
< button onclick = "myGeeks()" >
Click Here!
</ button >
< p id = "result" ></ p >
< script >
function myGeeks() {
let x = document.getElementById("GFG").search;
document.getElementById("result").innerHTML = x;
}
</ script >
</ body >
</ html >
|
Output:
Example 2: This example sets the Anchor search property.
html
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM Anchor search Property
</ title >
</ head >
< body style = "text-align: center;" >
< h1 >GeeksforGeeks</ h1 >
< h2 >HTML DOM Anchor search Property</ h2 >
< p >Welcome to
< a href =
id = "GFG" target = "_self" >
GeeksforGeeks
</ a >
</ p >
< button onclick = "myGeeks()" >
Click Here!
</ button >
< p id = "result" ></ p >
< script >
function myGeeks() {
let x = document.getElementById("GFG").search
= "post_id=987654&name=gfg";
document.getElementById("result").innerHTML
= "Anchor Search Change to " + x;
}
</ script >
</ body >
</ html >
|
Output:
Supported Browsers:
- Google Chrome 1
- Edge 12
- Firefox 1
- Opera 15
- Safari 1
Share your thoughts in the comments
Please Login to comment...