jQuery on() method not working for appended elements
Posted
by
behz4d
on Stack Overflow
See other posts from Stack Overflow
or by behz4d
Published on 2012-10-27T09:02:00Z
Indexed on
2012/10/27
11:01 UTC
Read the original article
Hit count: 147
jQuery
I know I should use on() method for triggering appended elements and not use click(), so:
$('#change_profile_img').on('click', function(){
alert(1);
});
so the above code is working fine on any elements unless the appended elements, for example, I'm appending:
$('.companylogo:first').append('<a id="change_profile_img" class="ic_change">CHANGE IMAGE</a>');
after it's appended, it's not working, but after a page refresh it works just fine. Another thing that I should mention, I'm doing the append from a modal page, it appends the button and everything but I could not trigger it anymore...
I would appreciate any kind of help. Thanks
© Stack Overflow or respective owner