XML DOM getAttribute() विधि

वर्णन और उपयोग

getAttribute() यह विधि नाम के द्वारा एट्रिब्यूट मान प्राप्त करती है。

व्याकरण

elementNode.getAttribute(name)
पारामीटर वर्णन
name अनिवार्य

उदाहरण

इस कोड के माध्यम से "books.xml" को xmlDoc में लोड किया जाता है और सभी <book> एलीमेंट के "category" एट्रिब्यूट के मान प्राप्त किए जाते हैं:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
    var x, i, xmlDoc, txt;
    xmlDoc = xml.responseXML;
    txt = "";
    x = xmlDoc.getElementsByTagName('book');
    for (i = 0; i < x.length; i++) {
        txt += x[i].getAttribute('category') + "<br>";
    }
    document.getElementById("demo").innerHTML = txt;
}

स्वयं अभिप्राय से प्रयोग करें