Getting text values of li (even nested) in JQuery

Posted by Tahir Akram on Stack Overflow See other posts from Stack Overflow or by Tahir Akram
Published on 2011-01-07T06:48:45Z Indexed on 2011/01/07 6:53 UTC
Read the original article Hit count: 363

Filed under:
|
|
|

Hi;

<ul>
  <li class="item-i">AI</li>
  <li class="item-ii">AII
    <ul class="level-2">
      <li class="item-a">A</li>
      <li class="item-b">B</li>
      <li class="item-c">C</li>
    </ul>
  </li>
  <li class="item-iii">III</li>
</ul>

How can I get values AI AII A B C III?

What I tried so far is following:

$(document).ready(function() {
    $('li').each(function(index) {
     alert($(this).text());
    });
});

But it does not gave me required results. When it reaches "item-ii" it gave all result.

I want item one by one.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about dom