Why :odddoes the selector not work when I pass it to a function remove(selector)? According to the documentation , it should filter out the already selected set of elements, which in this case is li.
<ul id='list1'>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ul>
<ul id='list2'>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ul>
$(document).ready(function() {
$('#list1').children(':odd').remove();
$('#list2').children().remove(':odd');
});
Result
-One
-Three
-One
-Two
-Three
-Four
source
share