XML DOM hasAttribute() మార్గదర్శకం
నిర్వచనం మరియు ఉపయోగం
ప్రస్తుత ఎలమెంట్ నుండి కొన్ని నామం కలిగిన అంశాన్ని కలిగి ఉంటే hasAttribute()
ఈ మార్గదర్శకం సత్యం అయితే true తిరిగి ఇస్తుంది, లేకపోతే false తిరిగి ఇస్తుంది.
సంకేతం
hasAttribute(name)
పారామితులు | వివరణ |
---|---|
name | అవసరం. కనుగొనే అంశాన్ని నిర్దేశిస్తుంది. |
ఉదాహరణ
ఈ కోడు "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.hasAttribute("category"); }