Agi la
Agi la

Reputation: 137

Jquery - onclick not triggered for dynamic created elements

I have an issue, Jquery onclick not triggered for dynamic created elements. I am using Jquery 1.9 and tried the example with "ON" and "LIVE". But still its not working. can some 1 help me?.

$("input[type=checkbox]").on("click", function (e) {..});

Demo: Fiddle

Upvotes: 0

Views: 381

Answers (3)

mmpatel009
mmpatel009

Reputation: 941

Please add your function into document.ready

$(document).ready(function(){
    $("input[type=checkbox]").on("click", function (e) {..});
})

I think it will help you to solve your issue.

Demo: fidder

Upvotes: 0

Prakash GPz
Prakash GPz

Reputation: 1523

If you have create and append elements using javascript, you have to set new event handler for that. event handlers set before adding the elements will not work for those elements.

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

Change the event handler to

$(document).on("click", "input[type=checkbox]", function (e) {

Upvotes: 1

Related Questions