36

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" />

2
  • I don't see where is the #activelist container? Commented Jun 19, 2012 at 22:40
  • 1
    It's not a container, it's a faulty selector (typo and space, I think). Commented Jun 19, 2012 at 22:42

3 Answers 3

54

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

$('#inactivelist').change(function () {
    alert('changed');
 });
2
  • do you know what is #activelist?
    – Ram
    Commented Jun 19, 2012 at 22:42
  • You realise there's a typo in the id of his posted mark-up, right? Commented Jun 19, 2012 at 22:42
7
$('input[type=checkbox]').change(function () {
    alert('changed');
});
6

There is a typo error :

$('#activelist :checkbox')...

Should be :

$('#inactivelist:checkbox')...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.