How can I remove duplicate values -> drop down option elements?
I have the following HTML:
# This is other quick option iterating options, counting the duplicates and remove when are more than one#
var opt = $("select[title='Country'] option");
$.each(opt, function (key, value) {
var len = $("select[title='Country'] option:contains(" + value.text + ")").length;
if (len > 1)
{
value.remove();
}
});
Not tested, but something like this should work
var values = new Array();
$('#YourSelect').children('option').each(function() {
var text = $(this).text();
if (values.indexOf(text) === -1) {
values.push(text);
} else {
// Its a duplicate
$(this).remove()
}
}