JQuery: non selector not working in

I have the following html code:

<ul>
                <li class="O">
                    <label for="radio1">Radio 1:</label>
                    <input type="radio" name="radio1" value="Yes" checked>Yes</input>
                    <input type="radio" name="radio1" value="No">No</input>
                </li>
                <li class="O">
                    <label for="checkbox1">Checkbox 1:</label>
                    <input type="checkbox" name="checkbox1" id="checkbox1" value="check"></input>
                </li>
            </ul>

Using jQuery, I would like to do something with every checkbox that is not checked, or an element with an empty value inside the li element with class O. This is my approach:

$('li').each(function(){
        if ($(this).hasClass('O')){
            $(this).children(':not(label,input:radio)').each(function(){
                if ( $(this).val() == "" || $(this).is(':checkbox:not(:checked)') ) {
                    //do something
                }
            });
        }

This code works with FF, Opera, Chrome and Safari, but not in IE6-IE7.

In both IEs, getting the li length with $ (this) .children (': not (label, input: radio)'). length returns 2, other browsers return 0 and 1.

Also, getting the first number of children that is not a label ($ (this) .children (': not (label)'). Length) returns 4, receiving the number of children ($ (this) .children (). Length) returns 2 It makes no sense to me at all.

Am I mistaken or is there something in the selector used that is not fully compatible with IE?

Thanks in advance.

+3
1

, , , li O. IE , . ?

$('li.O').each(function(){
    $(this).children(':checkbox:not(:checked)').each(function(){
        //stuff
    });
});

: :

$('li.O').each(function(){
    $(this).children(':checkbox:not(:checked), :not(label,input:radio)[value=]').each(function(){
        //stuff
    });

});

+1

Source: https://habr.com/ru/post/1743941/


All Articles