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?
JavaScript
x
29
29
1
function bind_remove(comment){
2
var id = comment.attr('comment_id');
3
comment.find(".remove").livequery("click", function(e){
4
$.post("/deleteComment", {id: id}, function(response){
5
comment.remove();
6
comments = comments_container.find('.comment');
7
});
8
});
9
}
10
11
$(document).ready(function(){
12
13
var comments_container = $('#comments_container');
14
var comments = comments_container.find('.comment');
15
16
comments.each(function(){
17
bind_remove($(this));
18
});
19
20
$(".submit_button").livequery("click", function(e){
21
$.post("/newComment", {text: textarea.val()}, function(response){
22
comments_container.last().append($(response).fadeIn('slow',function(){
23
comments = comments_container.find('.comment');
24
bind_remove(comments.last());
25
}));
26
});
27
});
28
});
29
Advertisement
Answer
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