Mounir Federere Mounir Federere - 9 months ago 31
Javascript Question

jquery to pure javascript remove duplicate elments

i have this script to remove duplicate elements by class using jquery, is there a way to do it with pure javascript? this is my code

<script >$(document).ready(function() {
var seen2 = {};
$('.listofarticlescolor').each(function() {
var txt2 = $(this).text();
if (seen2[txt2])
seen2[txt2] = true;



Try this code, to make it work first you have to convert the list of nodes in an array, then do something similar to what you've done.

var classWillRemove = []'listofarticlescolor'));
var seen2 = {};
for(i=0;i< classWillRemove.length;i++){
     var text = classWillRemove[i].innerHTML;
     if (seen2[text]){
    } else {
         seen2[text] = true;

Demo :