I have a checkbox with an id of activelist
I tried the following but did not seem to work (I have below in) :
$(document).ready(function () { $('#activelist :checkbox').change(function () { alert('changed'); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="checkbox" id='inactivelist' value="inactivelist" />
“jquery check if checkbox is checked onchange” Code Answer's$( "SELECTOR" ). prop( "checked" ) // Returns true if checked, false if unchecked. $( "SELECTOR" ).is( ":checked" ) // Returns true if checked, false if unchecked.
To check whether a Checkbox has been checked, in jQuery, you can simply select the element, get its underlying object, instead of the jQuery object ( [0] ) and use the built-in checked property: let isChecked = $('#takenBefore')[0]. checked console. log(isChecked);
Checking if a checkbox is checked First, select the checkbox using a DOM method such as getElementById() or querySelector() . Then, access the checked property of the checkbox element. If its checked property is true , then the checkbox is checked; otherwise, it is not.
There is no need to use :checkbox
, also replace #activelist
with #inactivelist
:
$('#inactivelist').change(function () { alert('changed'); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With