Here is the code snippet that I am currently working with:
$(function() {
$('li:lt(5)').css("background", "red");
});
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<div id="listes">
<ul id="ul1">
<li>
Element de liste 1
<ul id="ul2">
<li>Enfant 1</li>
<li>Enfant 2</li>
</ul>
</li>
<li>Element de liste 2</li>
<li>Element de liste 3</li>
<li>Element de liste 4</li>
</ul>
</div>
I was expecting both of the last two li
's to remain unaffected, but only the very last one remained unchanged.
(As per the documentation: The :lt()
selector targets all elements at an index less than the specified index within the matching set.)
Can someone explain why this behavior is occurring?