Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
163
rated 0 times [  166] [ 3]  / answers: 1 / hits: 16255  / 14 Years ago, fri, october 1, 2010, 12:00:00
<ul id=myid>   
<li>microsoft</li>
<li>microsoft</li>
<li>apple</li>
<li>apple</li>
</ul>


I want to remove duplicates from li by using jquery.



How can I do that?


More From » jquery

 Answers
8

example
I find that the script is faster



var liText = '', liList = $('#myid li'), listForRemove = [];

$(liList).each(function () {

var text = $(this).text();

if (liText.indexOf('|'+ text + '|') == -1)
liText += '|'+ text + '|';
else
listForRemove.push($(this));

})​;

$(listForRemove).each(function () { $(this).remove(); });

[#95448] Tuesday, September 28, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devonw

Total Points: 311
Total Questions: 116
Total Answers: 111

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
;