「Javascript」liの子要素を取得するコード

サンプルコード
<strong>data source</strong>
<ul>
<li>test one</li>
<ul>
<li>test_one</li>
<li>test_two</li>
<li>test_three</li>
</ul>
<li>www.sample.net</li>
<li>www.test.com</li>
</ul>

<script>
document.write(“<strong>outer ul li contents</strong><br>");
var tree1 = document.getElementsByTagName(“ul")[0].childNodes;
for (var i = 0;i < tree1.length;i++){
document.write(tree1[i].innerHTML);
}

document.write(“<br><br><strong>inner ul li contents</strong><br>");

var tree2 = document.getElementsByTagName(“ul")[1].childNodes;
for (var i = 0;i < tree2.length;i++){
document.write(tree2[i].innerHTML);
}

</script>

JavaScript

Posted by arkgame