How can I iterate through an Elements child nodes using Javascript?

前端 未结 1 980
臣服心动
臣服心动 2020-12-21 09:01

I\'m trying to iterate through a DOM elements children and display their attributes in my code:

document.write(\"\");
var testcasei         
相关标签:
1条回答
  • 2020-12-21 09:38
    var testcaseiterator = xmlDoc.getElementsById("tc").childNodes;
    

    The rest of the code looks okay.

    for(i=0; i < testcaseiterator.length; i++)
     {
         document.write("<tr><td>");
         document.write(testcaseiterator[i].getAttribute('name'));
         document.write("</td></tr>");
     }
     document.write("</table>")
    

    You will also have to edit the 5th line of the XML,

     <TestCase id ="tc"  name="Visit all buttons [in region Button: Navi 0]">
    

    This will only work if you XML in your DOM structure.

    0 讨论(0)
提交回复
热议问题