HTML DOM एंकर हैश प्रॉपर्टी का उपयोग href विशेषता मान के एंकर भाग को सेट या वापस करने के लिए किया जाता है। # के बाद URL का वह भाग जिसे हम लिंक का एंकर भाग कहते हैं।
हैश प्रॉपर्टी सेट करने के लिए सिंटैक्स निम्नलिखित है -
anchorObject.hash = anchor_part
ऊपर, एंकर_पार्ट यूआरएल का एंकर हिस्सा है।
हैश प्रॉपर्टी को वापस करने के लिए सिंटैक्स निम्नलिखित है -
anchorObject.hash
आइए अब DOM एंकर हैश प्रॉपर्टी को लागू करने के लिए एक उदाहरण देखें -
उदाहरण
<!DOCTYPE html>
<html>
<body>
<h1>Company</h1>
<p><a id="mylink" href="http://www.demo.com/abc/def.html#myteam">Our Team</a></p>
<p>Get the anchor part...</p>
<h2 id="myid"></h2>
<button onclick="display()">Display Anchor Part</button>
<script>
function display() {
var a = document.getElementById("mylink").hash;
document.getElementById("myid").innerHTML = a;
}
</script>
</body>
</html> आउटपुट

अब, लिंक के एंकर भाग को प्रदर्शित करने के लिए बटन पर क्लिक करें -
