特定のクラス名を持つすべてのドロップダウン選択をループしてアイテムを追加したいのですが、正しいセレクターで苦労しています
編集: 賛成された受け入れられた答えのほとんどが機能していないように見えるので、私は何か間違ったことをしているに違いありません。以下のHTMLとjqueryコードの両方を貼り付けました。これが理にかなっている場合はお知らせください。
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>
など。。。
jqueryコード:
$('select.componentSelect').each(function() {
var select = $(this);
$(select).children('option').each(function() {
if ($(this).text() == currentComponentName) {
$(this).remove();
}
});
});