Reputation: 563
I have this ul li list:
<ul>
<li><div>Text</div><a href="#">A</a></li>
<li><div>Text</div><a href="#">B</a></li>
<li><div>Text</div><a href="#">C</a></li>
<li>
<ul>
<li><div>Text</div><a href="#">A1</a></li>
<li><div>Text</div><a href="#">B1</a></li>
<li><div>Text</div><a href="#">C1</a></li>
<li><div>Text</div><a href="#">D1</a></li>
</ul>
</li>
<li><div>Text</div><a href="#">E</a></li>
</ul>
I need to choose all "li" element from the first level.
In this example it will be:
<li><div>Text</div><a href="#">A</a></li>
<li><div>Text</div><a href="#">B</a></li>
<li><div>Text</div><a href="#">C</a></li>
<li><div>Text</div><a href="#">E</a></li>
Trying to use:
$('ul').children()
I get all "li" elements from the first level and second level.
Thank you very much.
Upvotes: 0
Views: 1350
Reputation: 11
You can use following code which will search for 1st ul and then all li's: $('ul:first>li')
Upvotes: 1
Reputation: 496
You could change your selector to
$("'whatever element is above first level ul element' > ul > li")
Upvotes: -1
Reputation: 10466
Select li
of ul:first
which doesnot has a ul
element as child.
$('ul:first').children('li:not(:has(ul))');
Upvotes: 4
Reputation: 2703
try
$('ul>li').css(//your doing//);
This will select the direct childs
of the all ul tags
in your code.
If you want to acess specific ul
, try givig it a class
or id
.
Upvotes: 0
Reputation: 846
Give the external ul a class:
<ul class="my_ul">
....
</ul>
and in jquery you an get them like:
$('.my_ul').children()
EDIT: my first code was getting al children.
Upvotes: -1