I am using following selector to remove single item in select.
jQuery("#stateCity option[value='Adak, AK, USA']").remove();
I want a selector that can remove all cities of a state. Like *, AK, USA will remove all cities of Alaska in the combo.
So what regex I should use to do it in one line? Of if I have to loop it. How can I do that.
<select name="stateCity" id="stateCity">
<option value="Adak, AK, USA">Adak, AK, USA</option>
<option value="Akhiok, AK, USA">Akhiok, AK, USA</option>
<option value="Redwood, CA, USA">Redwood, CA, USA</option>
<option value="AL, USA">AL, USA</option>
</select>
Try this
jQuery("#stateCity option[value$='AK, USA']").remove();Demo: http://jsfiddle.net/8cuYM/
$=selects any element that the value ends with that you specified, in this caseAK, USA.Read more at http://api.jquery.com/attribute-ends-with-selector/