I have a select menu that is populated dynamically (via a Wordpress plugin) that I need to remove options that don't exist in my array values.
The items in the array will always need to be in my select menu.
I'm trying to do this by comparing the text value of the option. Here is what I have so far. Once I introduced the array I wasn't sure how to iterate through each option and compare against the array items.
jQuery("select[name*='vehicles'] > option").each(function()
{
var myGroups = ["Cars", "Bikes", "Airplanes", "Motorcycles"];
jQuery.each(myGroups, function(index, value) {
if(jQuery(this).text() != value) {
jQuery(this).remove();
}
});
});