Jquery on (’click’) does not start after the first click

I have some HTML:

Profile Picture

And with that, I have some Jquery:

$('.posts-content').on('click', '.post-delete', function(e) {
                if (confirm('Are you sure you want to delete this post?')) {
                    var $this = $(this);
                        url: '/a/delete_post',
                        type: 'POST',
                        dataType: 'json',
                        data: {'p' : post_id},
                        success: function() {
                            return true;
                return false;

Everything works perfectly the first click, but if I go to another post, and try to click .post-delete
, the event never fires, and nothing shows up in the console. It also works if I use $.click()
, but I need to dynamically create elements. Why does the $.on('click')
not fire the second click?

My guess is that dropdown plugin you use change the DOM structure.



this is really really bad practice.

You should use closest

Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 前端开发 » Jquery on (’click’) does not start after the first click

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录