Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery checkbox onChange

Tags:

jquery

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" />
like image 621
Nate Pet Avatar asked Jun 19 '12 22:06

Nate Pet


People also ask

How do you check checkbox is checked or not Onchange jQuery?

“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.

Is checkbox checked jQuery?

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);

How do I check if a checkbox is checked in an event?

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.


1 Answers

There is no need to use :checkbox, also replace #activelist with #inactivelist:

$('#inactivelist').change(function () {     alert('changed');  }); 
like image 66
mgraph Avatar answered Sep 19 '22 15:09

mgraph