0
<ul id="tab">
  <li onclick="clicker()" class="li01">one test</li>
  <li onclick="clicker()" class="li02">two test</li>
  <li onclick="clicker()" class="li03">three test</li>
  <div class="web_clear"></div>
</ul>
<div class="web_index">
  content....
</div>

I used document.getElementsByTagName("ul").childNodes; to get all the li. But it doesn't work.

2
  • 1
    try this document.getElementsByTagName("ul")[0].childNodes Commented Sep 13, 2012 at 8:14
  • 2
    document.getElementsByTagName("li") Commented Sep 13, 2012 at 8:14

4 Answers 4

1
var list = document.getElementById('tab').getElementsByTagName('li');
Sign up to request clarification or add additional context in comments.

Comments

1
document.getElementsByTagName("li")

this should work it will return an array of elements

Comments

1

You can get a NodeList to iterate through by using getElementsByTagName() , like this:

var list_li = document.getElementById("tab").getElementsByTagName("li");

Comments

0

You can use the id

document.getElemensById("tab").childNodes;

Or if its the only ul then

document.getElementsByTagName("ul")[0].childNodes;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.