views:

84

answers:

2

Dear readers,

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

+4  A: 

Hi there.

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.

Cheers. Jas.

Jason Evans
Thank you. I adjusted your solution to my needs: $(function() { $('#IBE1_IBE_NurFlug1_ddl_Abflughafen > option[value*="TR"]').hide(); });
@ceyago - Ahh yeah, I misread your requirement. `remove()` actually gets rid of the `<option>` which isn't what you wanted. Using `hide()` works better.
Jason Evans
Ya its working fine. i have tried following.$("select > option[value$='TR']").remove()
Amit
As pointed here: http://stackoverflow.com/questions/2324250/style-displaynone-doesnt-work-on-option-tags-in-chrome-but-it-does-in-firefox, WebKit ignores display:none on option tags. So you should really remove and add them as you need.
clinisbut
A: 

Does anybody know why this is not working in the browsers MSIE 8 and Safari 5?

Same here, seems at least that WebKit (Safari and Chrome) ignores display:none on an option element.
clinisbut