0

I don't understand why livequery doesn't bind the event, but I have to use .click. This is just an example, which might also use the .click(), but in the real code I'm forced to use livequery. Does anyone know why livequery isn't working?

function bind_remove(comment){
    var id = comment.attr('comment_id');    
    comment.find(".remove").livequery("click", function(e){    
        $.post("/deleteComment", {id: id}, function(response){
            comment.remove();
            comments = comments_container.find('.comment');
        });    
    });
}

$(document).ready(function(){    

    var comments_container = $('#comments_container');
    var comments = comments_container.find('.comment');

    comments.each(function(){
        bind_remove($(this));
    });
    
    $(".submit_button").livequery("click", function(e){
    $.post("/newComment", {text: textarea.val()}, function(response){                    
        comments_container.last().append($(response).fadeIn('slow',function(){                    
                comments = comments_container.find('.comment');
                bind_remove(comments.last());                            
            }));
        });
    });
});
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
M4rk
  • 2,172
  • 5
  • 36
  • 70

2 Answers2

0

Try replacing

comment.find(".remove").livequery("click", function(e){

with this

comment.find(".remove").live("click", function(e){
Blender
  • 289,723
  • 53
  • 439
  • 496
  • Could you post more code? You cut it right in the middle of a function. – Blender Mar 27 '11 at 18:15
  • more code are about 1000 rows...I can try to change the existing code to make it more understandable... Read it now! ;) – M4rk Mar 27 '11 at 21:52
0

I added a random id to the last comment, then I selected it with $('#myid'), not using 'last()'. Then I bind it and started to work

M4rk
  • 2,172
  • 5
  • 36
  • 70