开发者

Problem with jquery live method

开发者 https://www.devze.com 2023-04-04 19:14 出处:网络
I have something like wall posts which have the option of \'remove\'. Since posts can be added any time hence I\'m using jquery live method for event handling.

I have something like wall posts which have the option of 'remove'. Since posts can be added any time hence I'm using jquery live method for event handling. The problem is, multiple events are getting attached to 'remove' on click event

$(document).ready(function(){
    $('.actions .remove_wall_post').live('click', function(){
                var wall_post_id = $(this).attr('id');
                var data = {
                  'action' : 'remove',
                  'wall_post_id' : wall_post_id
                };
                var url = myurl;
                $.post(url, data, function(response){
                    if(response == '1'){
                        $('#post_list #'+wall_post_id).hide();
                        var total_posts = $('#total_posts').text();
                    } else{
                        alert('ERROR');
                    }
                });
                return false;
            });
});

Suppose there are n posts, when I click on 're开发者_运维问答move' of any post, the first event works fine...but after that i get n ERROR alerts and all events have the same wall_post_id

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号