removing duplicates from html elements

前端 未结 6 1861
野趣味
野趣味 2020-12-21 17:49

what\'s the best way to remove the grapes duplicate from this? there are tons of ways of removing duplicates from simple arrays, but this would be an array with html element

6条回答
  •  太阳男子
    2020-12-21 18:25

    :has expects an element selector while :contains takes a string

    see http://api.jquery.com/contains-selector/

    so this should do the trick:

     $('.fruit').each(function () {
          $('.fruit:contains("' + $(this).text() + '"):gt(0)').remove();  
     });
    

    fiddle: http://jsfiddle.net/kam7E/

提交回复
热议问题