// count function function countElement(item, array) { var count = 0; $.each(array, function(i, v) { if (v === item) { count++; } }); return count; } // create array from ips in the list ipList = []; uaList = []; $('li.list').each(function(i) { var spans = $(this).children(); spans[0] = $(spans[0]); spans[1] = $(spans[1]); ipList[i] = spans[0].text(); uaList[i] = spans[1].text(); }); // check how many for each ip $('li.list').each(function(i) { var spans = $(this).children(); spans[0] = $(spans[0]); spans[1] = $(spans[1]); var ipText = $(spans[0]).text(); var uaText = $(spans[1]).text(); var count = countElement(ipText, ipList); //if more than one update class of span if (count > 1) { spans[0].addClass('i' + count); } var countua = countElement(uaText, uaList); //if more than one update class of span if (countua > 1) { spans[1].addClass('u' + count); } });