문제

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());                            
            }));
        });
    });
});
도움이 되었습니까?

해결책 2

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

다른 팁

Try replacing

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

with this

comment.find(".remove").live("click", function(e){
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top