jQuery load(), then use hide() on what's loaded
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
精彩评论