Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Check if checkbox is checked with jQuery

How might I check if a checkbox in a checkbox array is checked utilizing the id of the checkbox array?

I'm utilizing the accompanying code, however, it generally returns the count of checked checkboxes regardless of id.
function isCheckedById(id) {
alert(id);
var checked = $("input[@id=" + id + "]:checked").length;
alert(checked);

if (checked == 0) {
return false;
} else {
return true;
}
}
by

2 Answers

ninja01

$('#checkbox').is(':checked');

The above code returns true if the checkbox is checked or false if not.
kshitijrana14
All following methods are useful:
$('#checkbox').is(":checked")

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

$('#checkbox')[0].checked

$('#checkbox').get(0).checked

It is recommended that DOMelement or inline "this.checked" should be avoided instead jQuery on method should be used event listener.

Login / Signup to Answer the Question.