Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery没有';不要删除最后一个div_Javascript_Jquery_Html - Fatal编程技术网

Javascript jquery没有';不要删除最后一个div

Javascript jquery没有';不要删除最后一个div,javascript,jquery,html,Javascript,Jquery,Html,我想将tweet附加到一个空div中,但当tweet计数为5或更大时,我想从底部删除一个tweet,以便只显示5条tweet。我写的这段代码没有删除任何内容 var side = 'left'; cnt = 0; setInterval(function(){ $('.tweet-stream').prepend('<div class="tweet t'+side+'"></div><div class="t-header"></div>

我想将tweet附加到一个空div中,但当tweet计数为5或更大时,我想从底部删除一个tweet,以便只显示5条tweet。我写的这段代码没有删除任何内容

var side = 'left';
cnt = 0;
setInterval(function(){
    $('.tweet-stream').prepend('<div class="tweet t'+side+'"></div><div class="t-header"></div>');
    if(cnt%2==0){
        side='right';
    } else {
        side='left';
        if(cnt>=5){
            $("div[class=tweet]:last").remove();
        }
    }
    cnt++;
},3000);
var-side='left';
cnt=0;
setInterval(函数(){
$('.tweet-stream')。前置('');
如果(cnt%2==0){
“右边”;
}否则{
左边;
如果(cnt>=5){
$(“div[class=tweet]:last”).remove();
}
}
cnt++;
},3000);

使用
$('div.tweet:last')。删除()

使用
$('div.tweet:last')。删除()

看起来您只是在满足“左”条件时才移除最后一个吐温

这似乎在起作用:

var-side='left';
cnt=0;
setInterval(函数(){

$(“.tweet stream”).prepend(看起来您只是在满足“left”条件时删除了最后一个tween

这似乎在起作用:

var-side='left';
cnt=0;
setInterval(函数(){

$(“.tweet-stream”).prepend(“为什么
div[class=tweet]
?只要
div.tweet
对吗?@elclanrs如果你想把它作为答案发布,我会删除我的。你拿着它,感觉很懒:)为什么
div[class=tweet]
?只要
div.tweet
对吗?@elclanrs如果你想把它作为一个答案,我会删除我的。你拿着它,感觉很懒:)
$('.tweet-stream:last-child').remove();
var side = 'left';
cnt = 0;
setInterval(function () {
    $(".tweet-stream").prepend("<div class='tweet t" + side + "></div><div class='t-header'>tweet-" + cnt + "</div>");
    if (cnt % 2 == 0) {
        side = 'right';
    } else {
        side = 'left';
    }
    if (cnt >= 5) {
        $("div.tweet:last").remove();
    }
    cnt++;
}, 3000);