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

$('#checkbox_id').val();
$('.checkbox_class').val();

Without id

$("input[type='checkbox']").val();

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

But,

$('#checkbox').prop('checked')

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 *


2 × = ten

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>