javascript - $('.input:checked') behaves differently than $('.input[checked=checked]') -
take following scenario: have 2 radio buttons, both same name, , both checked (i realize that's invalid):
<input type="radio" class="input" name="cb1" checked="checked" /> <input type="radio" class="input" name="cb1" checked="checked" /> why following 2 selectors behave differently?
$('.input:checked').size(); // returns 1 $('.input[checked=checked]').size(); // returns 2 apparently, first selector returns checkbox occurs last in markup, while first selector returns both.
that's because :checked selector checks checked property of elements which different checked attribute.
Comments
Post a Comment