0

Here I am getting values from sqlite db,binding those values in javascript and showing it on html by calling id of that particular .In this process I reuired to put checkbox.I created it in javascript only not in html. so now i required to check the checkbox in dynamically created javascript. here I am pasting my code. Thanks in advance for your valuable suggestions.

$('#lightsList').append('<li style="background:#666666">'+
            '<img src="../images/' + light.ledLightImage + '" class="ui-li-thumb" style="margin-left: 10px; margin-top:2px;"/>' +
            '<form id="checkbox" style="padding-top:18px; color:#ffffff">'+
            '<input type="checkbox" name="Tick" value="Tick" class="regular-checkbox" onclick="checked()"/><br>Tick'+
            '</form>' +
            '<p class="line1">' + light.ledLightName  + '</p>' +
            '</li>'+
            '<li style="display:none;">'+light.ledWattage+'</li>');
2
  • Do u want to bind check event of dynamically added checkboxes? Commented Apr 30, 2014 at 6:10
  • Then follow any of the answer below. It will work Commented Apr 30, 2014 at 6:42

2 Answers 2

1

You need to use on() for event delegation like,

$('#lightsList').on('click', '.regular-checkbox', function() {
    checked();// call your function checked here
});
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

$(document).on('change', '.regular-checkbox', function() {
    // event handler
});

Comments

Your Answer

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