Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery: Hide options of select according to option value

given following html

<select name="IBE1$IBE_NurFlug1$ddl_Abflughafen" id="IBE1_IBE_NurFlug1_ddl_Abflughafen" class="dropdownlist" style="width: 99%;">
<option value="Antalya;TR">Antalya</option>
<option value="Berlin;DE">Berlin</option>
<option value="Duesseldorf;DE">Duesseldorf</option>
<option value="Frankfurt;DE">Frankfurt</option>
<option value="Hamburg;DE">Hamburg</option>
<option value="Hannover;DE">Hannover</option>
<option value="Köln-Bonn;DE">Köln-Bonn</option>
<option value="Leipzig;DE">Leipzig</option>
<option value="München;DE">München</option>
<option value="Stuttgart;DE">Stuttgart</option>

How can I hide all options with ;TR in the value?

thx a lot in advance, greetings

like image 710
user168507 Avatar asked Jul 02 '10 09:07

user168507


People also ask

How can I show and hide elements based on selected option with jQuery?

If you want to hide/show div on dropdown selected, use the jQuery hide() and show(). Before you perform hide or show div on dropdown selection, you need to hide them first using CSS display:none.

How do I hide a selection option?

The hidden attribute hides the <option> element. You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <option> element is not visible, but it maintains its position on the page.

Which method in the jQuery used for hide the selected elements?

The hide() method hides the selected elements.

How do I iterate through select options in jQuery?

Iterate through <select> options using jQuery To traverse the <select> tag, a function has to be created which will return the text, value, or both (text and value) of the options in it. For this, each() method of jQuery will be used. Using this, elements can be traversed easily.


1 Answers

Try

$("select > option[value*='TR']").remove()

EDIT:

Or if you know that 'TR' is always at the end, then

$("select > option[value$='TR']").remove()

Not sure how much more efficient the above is compared to searching the entire value attribute.

like image 119
Jason Evans Avatar answered Sep 19 '22 06:09

Jason Evans