hasChildNodes()

XML DOM hasChildNodes() metodi


❮ Element obyekti

Misol

Quyidagi kod fragmenti "books.xml" faylini xmlDoc’ga yuklaydi va birinchi <book> elementida biror bola tugun bor-yo‘qligini tekshiradi:

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

Yuqoridagi kodning natijasi quyidagicha bo‘ladi:

true
O‘zingiz sinab ko‘ring »

Ta’rif va qo‘llanilishi

Agar joriy element tugunida bola tugunlar bo‘lsa, hasChildNodes() metodi TRUE, aks holda FALSE qaytaradi.

Sintaksis

elementNode.hasChildNodes()

❮ Element obyekti

W3Schools Pathfinder

Yutuqlaringizni kuzating – bu bepul!