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

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -