user3488098
user3488098

Reputation:

how to check checkbox event dynamically created in javascript using jquery mobile

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

Upvotes: 0

Views: 617

Answers (2)

Rohan Kumar
Rohan Kumar

Reputation: 40639

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

$('#lightsList').on('click', '.regular-checkbox', function() {
    checked();// call your function checked here
});

Upvotes: 1

Manoj Yadav
Manoj Yadav

Reputation: 6612

Try this:

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

Upvotes: 0

Related Questions