Advertisement
amoussa11

DOM Node List Length

Feb 17th, 2019
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 0.62 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <p id="demo"></p>
  6.  
  7. <script>
  8. var xhttp;
  9. xhttp = new XMLHttpRequest();
  10. xhttp.onreadystatechange = function() {
  11.     if (this.readyState == 4 && this.status == 200) {
  12.        myFunction(this);
  13.     }
  14. };
  15. xhttp.open("GET", "books.xml", true);
  16. xhttp.send();
  17.  
  18. function myFunction(xml) {
  19.     var x, i, txt, xmlDoc;
  20.     xmlDoc = xml.responseXML;
  21.     txt = "";
  22.     x = xmlDoc.getElementsByTagName("title");
  23.     for (i = 0; i < x.length; i++) {
  24.        txt += x[i].childNodes[0].nodeValue + "<br>";
  25.     }
  26.     document.getElementById("demo").innerHTML = txt;
  27. }
  28. </script>
  29. </body>
  30. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement