Reputation: 29
In this code why does it use children('li')
because when you select children it obviously selects all the children.
$('ul.emphais').children('li').eq(3).prev().text('added with jQuery');
Upvotes: 0
Views: 47
Reputation: 2774
Since ul
should ideally contain only li
as children, children('li')
will have same meaning as children()
ideally.
But if you have something like this which is still allowed syntactically (not recommended), it means different:
<ul id="list">
<li>1</li>
<li>2</li>
<li>3</li>
<div>4<div>
</ul>
alert($("#list").children("li").length); //Alerts 3 with and without the <div>
alert($("#list").children().length); //Alerts 4 and 3 with and without the <div>
Upvotes: 1