एंकर टैग से जुड़ी HTML DOM type प्रॉपर्टी लिंक के type एट्रिब्यूट के मान को सेट या प्राप्त करने के लिए उपयोग की जाती है। यह एट्रिब्यूट HTML 5 में पेश किया गया था। यह एट्रिब्यूट केवल सुझाव के लिए है और इसे शामिल करना अनिवार्य नहीं है। इसमें एकल MIME (मल्टीपर्पस इंटरनेट मेल एक्सटेंशन) मान प्रकार होता है।
सिंटैक्स
निम्नलिखित सिंटैक्स है -
type प्रॉपर्टी लौटाना -
anchorObject.type
type प्रॉपर्टी सेट करना -
anchorObject.type = MIME-type
उदाहरण
आइए anchor text प्रॉपर्टी का एक उदाहरण देखें -
<!DOCTYPE html> <html> <body> <p><a id="Anchor" type="text/html" href="https://www.examplesite.com">example site</a></p> <p><a id="Anchor2" href="https://www.example.com">example</a></p> <p>Click the buttons to set and get the type attribute.</p> <button onclick="getType1()">GetType</button> <button onclick="setType2()">SetType</button> <p id="Type1"></p> <script> function getType1() { var x = document.getElementById("Anchor").type; document.getElementById("Type1").innerHTML = x; } function setType2(){ document.getElementById("Type1").innerHTML="Type has been set"; document.getElementById("Anchor2").type="text/html"; } </script> </body> </html>
आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा -

GetType बटन पर क्लिक करने पर -

SetType बटन पर क्लिक करने पर -

उपरोक्त उदाहरण में -
हमने id Anchor और Anchor2 के साथ दो लिंक्स लिए हैं। Anchor1 के साथ MIME type text/html जुड़ा हुआ है जबकि Anchor2 के साथ कोई MIME type जुड़ा हुआ नहीं है।
<p><a id="Anchor" type="text/html" href="https://www.examplesite.com">example site</a></p> <p><a id="Anchor2" href="https://www.example.com">example</a></p>
फिर हमारे पास GetType और SetType नाम के दो बटन हैं जो क्रमशः getType1() और getType2() फ़ंक्शन को निष्पादित करते हैं।
<button onclick="getType1()">GetType</button> <button onclick="setType2()">SetType</button>
getType1() फ़ंक्शन इससे जुड़े “Anchor” id वाले एंकर टैग का type लौटाता है। setType2() फ़ंक्शन “Anchor2” id वाले एंकर टैग के type को text/html पर सेट करता है।
function getType1() { var x = document.getElementById("Anchor").type; document.getElementById("Type1").innerHTML = x; } function setType2(){ document.getElementById("Type1").innerHTML="Type has been set"; document.getElementById("Anchor2").type="text/html"; }