Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> HTML

HTML DOM Anchor type प्रॉपर्टी


एंकर टैग से जुड़ी 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>

आउटपुट

यह निम्नलिखित आउटपुट उत्पन्न करेगा -

HTML DOM Anchor type प्रॉपर्टी

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

HTML DOM Anchor type प्रॉपर्टी

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

HTML DOM Anchor type प्रॉपर्टी

उपरोक्त उदाहरण में -

हमने 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"; }

  1. HTML DOM एंकर hostname प्रॉपर्टी: URL से डोमेन नाम प्राप्त करना HTML DOM एंकर hostname प्रॉपर्टी: URL से डोमेन नाम प्राप्त करना

    HTML DOM एंकर hostname प्रॉपर्टी URL का केवल होस्टनेम (डोमेन नाम) लौटाती है। यह पोर्ट नंबर, पाथ या क्वेरी पैरामीटर्स शामिल नहीं करती। सिंटैक्स होस्टनेम सेट करना: anchorObj.hostname = hostname होस्टनेम प्राप्त करना: anchorObj.hostname उदाहरण: hostname, host और hash की तुलना <!DOCTYPE html> &

  1. HTML DOM Ol type प्रॉपर्टी HTML DOM Ol type प्रॉपर्टी

    HTML DOM Ol type प्रॉपर्टी ऑर्डर्ड लिस्ट में उपयोग किए जाने वाले मार्कर के प्रकार को दर्शाने वाले type एट्रिब्यूट के मान को सेट या लौटाती है। सिंटैक्स olObject.type मान सेट करना olObject.type = 1|a|A|i|I उदाहरण <!DOCTYPE html> <html> <head> <title>HTML DOM Ol type</title&

  1. HTML DOM Event type प्रॉपर्टी HTML DOM Event type प्रॉपर्टी

    HTML DOM Event type प्रॉपर्टी इवेंट के प्रकार जैसे click, keypress, load, या touchend को दर्शाने वाला स्ट्रिंग लौटाती है। सिंटैक्स event.type उदाहरण <!DOCTYPE html> <html> <head> <title>HTML DOM Event type</title> <style>    form {