jQuery get checkbox value

You can I get a checkbox’s value in jQuery like this if you have set a class or id for it


Without id


For some reason:
•$(‘#checkbox’).val() always returns on
•$(‘#checkbox’).is(‘checked’) always returns false



Returns the right checkbox state.

Other way of retrieving checkbox’s value is

if ( elem.checked ) 
if ( $( elem ).prop( "checked" ) ) 
if ( $( elem ).is( ":checked" ) )

By Keenlio, March 12, 2014

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

− five = 3

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>