开发者

jq compare a list of elements and find odd one out

hi is there a way to compare a few elements

lets say

<ul>
   <li>Cat</li>
   <li>Dog</li>
</ul>

if i use ajax it returns

<ul>
   <li>Ant</li>
   <li>Cat</li>
   <li>Dog</li>
   <li>Fish</li>
</ul>

i need to blink ant and fish to indicate they are new ther开发者_JAVA技巧e.

any ideas ?


Its not quite obvious what you want, but maybe something like this (looks for matching text of li in existing ul ands add a class 'new' for new li's found and append them to the existing ul?) :

$currentUl = $('ul'); // this is the 'ul' with its li children u have on the page
//responseUl is the 'ul' string ur getting from the ajax call
$(responseUl).children('li').each( function (index, elem){
    if ( $currentUl.find(':[innerHTML=' + $(elem).text() + ']').length < 1 ){
        $currentUl.append( $(elem).addClass('new' ));
    }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜