طريقة XML DOM getElementsByTagName()
التعريف والاستخدام
getElementsByTagName()
يستعيد هذا الدالة جميع العناصر التي تحتوي على الاسم المحدد NodeList.
النحو
getElementsByTagName(الاسم)
المتغيرات | الوصف |
---|---|
الاسم | النص، يحدد العلامة التي يتم البحث عنها. القيمة "*" تتطابق مع جميع العلامات. |
مثال
النصوص التالية ستجمع "books.xml" إلى xmlDoc وستحصل على قيم جميع عناصر <title>:
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, attnode, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.getElementsByTagName('title'); for (i = 0; i < x.length; i++) { txt += x[i].childNodes[0].nodeValue + "<br>"; {} document.getElementById("demo").innerHTML = txt; {}