XML DOM hasAttributes() ਮੱਥਦ

ਵਿਆਖਿਆ ਅਤੇ ਵਰਤੋਂ

ਜੇਕਰ ਮੌਜੂਦਾ ਈਲੈਮੈਂਟ ਨੂੰ ਕੋਈ ਪ੍ਰਤੀਯੋਗਿਤਾ ਰੱਖਦਾ ਹੈ ਤਾਂ hasAttributes() ਮੱਥਦ ਮੁੱਲ ਵਾਪਰੇਗਾ true ਹੋਵੇਗਾ ਨਹੀਂ ਤਾਂ false ਵਾਪਰੇਗਾ。

ਵਿਧਾਨ

hasAttributes()

ਉਦਾਹਰਣ

ਇਹ ਕੋਡ "books.xml" ਨੂੰ xmlDoc ਵਿੱਚ ਲੋਡ ਕਰੇਗਾ ਅਤੇ ਪਹਿਲੇ <book> ਈਲੈਮੈਂਟ ਕੋਈ ਪ੍ਰਤੀਯੋਗਿਤਾ ਰੱਖਦਾ ਹੈ ਯਾਨੀ ਨਹੀਂ ਚੈਕ ਕਰੇਗਾ:

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 xmlDoc = xml.responseXML;
    var x = xmlDoc.getElementsByTagName('book')[0];
    document.getElementById("demo").innerHTML =
    x.hasAttributes();
}

亲自试一试