Martin Shinks
Martin Shinks

Reputation: 115

JQuery Checkbox Even

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 checkboxes 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

Answers (3)

Subhajit
Subhajit

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

Jon Taylor
Jon Taylor

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

gherkins
gherkins

Reputation: 14983

you can use jquery live, as it works on dynamically created elements.

$(":checkbox").live('change', function() {

http://jsfiddle.net/y6tCt/42/

Upvotes: 1

Related Questions