开发者

Jquery Ajax list element refresh, highlight new items?

开发者 https://www.devze.com 2022-12-28 05:26 出处:网络
What I\'m doing is refreshing a <ul&g开发者_StackOverflowt; that contains a load of tweets from twitter, is it possible to somehow highlight which items in the list are new since the refresh?

What I'm doing is refreshing a <ul&g开发者_StackOverflowt; that contains a load of tweets from twitter, is it possible to somehow highlight which items in the list are new since the refresh?

Thanks


Yes, at the time of your code refreshing the list, change the elements inside it to a default css class, and when you add the new ones, use another different css class with a different background color to highlight them.


Without an example of how you're fetching the tweets, it's hard to say.

However, if you can get some sort of ID for every tweet, you could store these in a variable as a simple list, e.g. [183481, 134588, 8384] (if the IDs are integers). When you later update the list of tweets, you compare the IDs you get against the IDs in this list. From there it should be pretty straight-forward.

If there are no IDs, you could just use the actual tweet message (possibly combined with the author of the tweet) as the ID. There are a lot of ways to do this really.


jQuery.get('/your-latest-tweets.xml', function (xml) {
  var theUl = $('your-ul');

  theUl.children('li').removeClass('new');

  $(xml).find('tweet').each(function () {
    theUl.append('<li class="new">' + $(this).text() + '</li>');
  });
});

Obviously it's not directly related to your scenario, as you've posted no code.

0

精彩评论

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