Search code examples
jqueryinputradio-buttonchecked

How to get selected input:radio


How come this works.

$('input:checked')

and this won't?

$('input').is(':checked')

Thanks.


Solution

  • The second version should use .filter() instead of .is().

    $('input').filter(':checked')
    

    It seems like .is() should work since there's a .not() method. But .not() is actually the opposite of .filter().