Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Web Technology by (20.3k points)

How can I get a checkbox's value in jQuery?

1 Answer

0 votes
by (40.4k points)

Use the code given below, to get the value of the Value attribute :

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

Or if you have set a class or id for it, you can:

$('#check_id').val();

$('.check_class').val();

This will return the same value whether it is checked or not, this can be confusing as it is different from the submitted form behavior.

Try using the code given below to check whether it is checked or not:

if ($('#check_id').is(":checked"))

{

  // it is checked

}

Related questions

0 votes
1 answer
asked Sep 2, 2019 in Web Technology by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...