开发者

jQuery load(), then use hide() on what's loaded

开发者 https://www.devze.com 2023-04-06 09:48 出处:网络
I\'m loading a series of <li>s and would t开发者_StackOverflowhen like to hide all but the first 9... I\'m using:

I'm loading a series of <li>s and would t开发者_StackOverflowhen like to hide all but the first 9... I'm using:

$(document).ready(function() {
    $("#myList").load("tweet-list.php");
    var refreshId = setInterval(function() {
        $("#myList").load('tweet-list.php', function() {
            $('#myList li:gt(8)').hide();
        });
    }, 120000);
   $.ajaxSetup({ cache: false });
}); 

But I cannot get the $('#myList li:gt(8)').hide(); part to work, and so the entire file shows... I imagine I need to use .live() but I'm not sure what event to use. Any help would be greatly appreciated!


I recommend loading them as hidden, and then explicitly showing the ones you want to see. The .hide() function runs asynchronously, and you could end up with some weirdness.


$('#myList li').filter(function(){ return $(this).index()>8; }).hide();

for example

0

精彩评论

暂无评论...
验证码 换一张
取 消