Reputation: 115
I have the following fiddle1 http://jsfiddle.net/y6tCt/35/ . I need to build the checkbox
list dynamically but for now I have hard coded two rows. When I click on one of the checkbox
es it is not invoking the 'change' event.
I would be grateful if someone could take a look and let me know what I have done wrong.
Upvotes: 0
Views: 67
Reputation: 1987
Checkout the script its now working, http://jsfiddle.net/y6tCt/46/
here is the script I changed,
buildHTML();
$(":checkbox").click(function() {
if( $(this).is(':checked') ) {
alert("Checked");
} else {
alert('Unchecked');
}
});});
Upvotes: 0
Reputation: 7905
The problem is that your dom is ready before the buildHTML(); has finished running.
Place the call to buildHTML(); as follows
$(document).ready( function() {
buildHTML();
$(":checkbox").change(function() {
alert("here");
});});
Upvotes: 2
Reputation: 14983
you can use jquery live, as it works on dynamically created elements.
$(":checkbox").live('change', function() {
Upvotes: 1