christina
christina

Reputation: 661

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

I'm loading a series of <li>s and would then 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!

Upvotes: 0

Views: 102

Answers (2)

Andy
Andy

Reputation: 30135

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

for example

Upvotes: 0

user610217
user610217

Reputation:

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.

Upvotes: 3

Related Questions