0

I would like to ask you a question about jQuery code, there was a problem when I tried to use on change jQuery event on new radio box which were cloned by jQuery.

Exactly it worked only first radio box element but the other no, so could you help me to solve this problem?

here is the code :

[http://jsfiddle.net/samphors/wg6fj6r5/][1]

thanks for your considering.

Samphors
  • 530
  • 9
  • 24
  • Problem is that the second radio button is being created dynamically. You might get an idea from here http://stackoverflow.com/questions/27976739/jquery-click-function/27976810 – Mritunjay Feb 24 '15 at 03:43

1 Answers1

0

You need to use event delegation.

Event delegation allows us to attach a single event listener, to a parent element, that will fire for all descendants matching a selector, whether those descendants exist now or are added in the future.

 $("body").on('change',"input[name='quiz_item_correct\\[\\]']",
        function(){
            if ($(this).is(':checked')) {   
               alert("check");
            }
        });

Demo

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125