सिंटैक्स
. के लिए सिंटैक्स निम्नलिखित है
-
a) खोज संपत्ति लौटाना
anchorObject.search
-
b) खोज गुण सेट करना
anchorObject.search = querystring
उदाहरण
आइए HTML DOM एंकर सर्च प्रॉपर्टी का एक उदाहरण देखें -
<!DOCTYPE html>
<html>
<body>
<p><a id="myAnchor" target="_blank"
href="http://www.examplesite.com/ex.htm?id=Username">Example Site</a></p>
<p>Click the button to change the querystring part of the above website</p>
<p>Inspect the url before clicking the button to inspect the changes</p>
<button onclick="demo()">Change Search</button>
<script>
function demo() {
document.getElementById("myAnchor").search = "program=Sample";
}
</script>
</body>
</html> आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा -
'फॉर्म आईडी दिखाएं' चेकबॉक्स चेक करने से पहले -

"खोज बदलें" बटन पर क्लिक किए बिना, लिंक इस प्रकार हैं -
www.examplesite.com/ex.htm?id=Username
"चेंज सर्च" बटन पर क्लिक करने के बाद लिंक होगा -
www.examplesite.com/ex.htm?prog=Sample
उपरोक्त उदाहरण में -
हमने सर्च प्रॉपर्टी के साथ एंकर टैग लिया है ताकि सर्च स्ट्रिंग वैल्यू को सेट करने या वापस करने के लिए सर्च प्रॉपर्टी वैल्यू में हेरफेर किया जा सके।
<p><a id="myAnchor" target="_blank" href="http://www.examplesite.com/ex.htm?id=Username">Example Site</a></p>
फिर हमने myFunction() -
. को निष्पादित करने के लिए "चेंज सर्च" नाम का एक बटन बनाया है<button onclick="demo()">Change Search</button>
myFunction() खोज स्ट्रिंग भाग को id="उपयोगकर्ता नाम" से प्रोग्राम=नमूना
में बदल देगाfunction demo() {
document.getElementById("myAnchor").search = "program=Sample";
}