i want to loop through all dropdown selects with a certain class name and add an item to it and i am just struggling with the correct selector
EDIT: I must be doing something wrong as most of the upvoted accepted answer dont seem to work so i think there must be some quirk in my code. I have pasted both the HTML and the jquery code below. let me know if this makes sense.
HTML:
<select onfocus="this.enteredText='';" onkeydown="return handleKey();" onkeyup="event.cancelbubble=true;return false;" onkeypress = "return selectItem();" class="componentSelect" id="components0" name="applicationUpdater.dependencies[0].componentName" >
<option value= 5 >Client</option>
<option value= 79 >Server</option>
</select>
<select onfocus="this.enteredText='';" onkeydown="return handleKey();" onkeyup="event.cancelbubble=true;return false;" onkeypress = "return selectItem();" class="componentSelect" id="components1" name="applicationUpdater.dependencies[0].componentName" >
<option value= 5 >Client</option>
<option value= 79 >Server</option>
</select>
etc . . .
jquery code:
$('select.componentSelect').each(function() {
var select = $(this);
$(select).children('option').each(function() {
if ($(this).text() == currentComponentName) {
$(this).remove();
}
});
});