Your mistake is that you're assuming that $.unique
compares the elements by their contents.
Whereas it just removes the exactly same nodes from the selection.
It could happen when you, say, use .add()
to concatenate one selection set with another.
UPD: the easiest solution I could think of is http://jsfiddle.net/6qe4c/2/
var div = $('div');
var values = [];
div.each(function() {
var $i = $(this),
value = $i.text();
if (values.indexOf(value) != -1) {
$i.remove();
return;
}
values.push(value);
});