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
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.
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.
The hide() method hides the selected elements.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With