I have a div “content”, in this div I have several div “comment”, I’m reloading the div “content” every 5 second, and I would like to fadeIn every new comments. For this, every comment has an id which is an integer, so basically what I’m doing is :
I’m saving the id of the last comment in a variable “lastComment”, and when I’m reloading the div “content”, I’m using if($(“.comment”).attr(id) > lastComment) { alert(‘ok’) }
But it doesn’t work, first it reloads the div and instead of saying ‘ok’ straight I need to wait 5 more seconds, here my code :
var lastComment = $('.comment:last').attr('id');
setInterval(function()
{
$('#content').load('fullscreen.php?image='+$('.imageBig').attr('id')+' #content');
if($('.comment').attr('id') > lastComment){
alert('ok');
}
}, 5000);
please any idea?
I think there is your
jQuery selectorproblem, in the if condition you should specify lastdiv.commentbecausevar lastComment = $('.comment:last').attr('id');statement will assign last element once after thissetIntervalworks and new last div comment will changed so alert not works.