مетод XML DOM hasAttributes()

تعریف و استفاده

اگر گره فعلی هرگونه ویژگی دارد، hasAttributes() این روش به "بله" برمی‌گردد، در غیر این صورت به "خیر".

نحوه استفاده

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();
}

صرف خود کا تجربہ کریں