removing duplicates from html elements

前端 未结 6 1862
野趣味
野趣味 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:35

    var uniqueFruits = [];
    $(".fruit").each(function(i,e){
        var thisFruit = $.trim($(e).text());
        if(uniqueFruits.indexOf(thisFruit) == -1)
            uniqueFruits.push(thisFruit);
        else
            $(e).remove();
    });
    

    http://jsfiddle.net/a7E9e/

提交回复
热议问题