jquery - Marking Only Some List Items with a Class -


i have following list item

<ul id="lxx" class="lst">   <li>arnold</li>   <li>becky</li>   <li>arnold</li>   <li>kathy</li>   <li>carol</li>   <li>arnold</li>       <li>carol</li>           </ul> 

i using code adds class 'someclass' items repeated more once.

$('#lxx li').filter(function(){     return $(this).siblings().text().touppercase()         .indexof($(this).text().touppercase()) != -1;   }).addclass('someclass'); 

however happens original item gets highlighted using above code, whereas want repeated items highlighted. out of arnold, arnold , arnold last 2 should highlighted. other dups too.

how can change code accommodate this? also there better way this?

try

var texts = {}; $('#lxx li').filter(function () {     var text = $.trim($(this).text().tolowercase());     if (texts[text]) {         return true;     }     texts[text] = this;     return false; }).addclass('someclass'); 

demo: fiddle


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -