Element added with jquery append does not trigger event

Asked

Viewed 667 times

1

I cloned a div that contains 2 elements: checkbox and button. The elements in the main div, of origin, trigger the events normally.

It turns out that after cloning the div with the elements inside, the created elements do not trigger any event. I tried several ways and it didn’t work.

Testing with part of my real code in Jsfiddle, it doesn’t work

Test with a code I created from scratch to test in Jsfiddle, it works

I can’t figure out why it doesn’t work in my real code. I wonder if you can help me?

1 answer

1


The problem is that the code generates a new element .status that there was before, of which this button .nova_subdemanda is descended.

Even though you’re already using event delegation you have to change $('.status').on(... for $(document).on(... or:

$('#lista_status').on('click','.nova_subdemanda', function(event){

jsFiddle: http://jsfiddle.net/666bnqfx/4/

  • I saw it there and the add new subdemanda (.nova_subdemanda) button works. But by doing the same with the checkbox element it behaves unexpectedly. It hides or displays the subderment list of the first status. You noticed that?

  • 1

    Ah! Forget it! Bobeei here. What will run after the event I set here. Thank you! Perfect! I had tried a lot of things, except this. ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.