Delete selector not working

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(); // works as expected
    $('#list2').children().remove(':odd'); // does not work
});

Result

-One
-Three

-One
-Two
-Three
-Four
+5
source share
2 answers

This is actually a bug: http://bugs.jquery.com/ticket/13721

And it was fixed 17 days ago in jQuery 2.0 .

The problem was that he checked if each element matched the selector:

for element in matched_elements:
    if element matches the selector:
        remove element

:odd , . , :even, .

+6

All Articles