5

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

user168507
  • 851
  • 4
  • 16
  • 33

1 Answers1

14

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.

Tim Cooper
  • 151,519
  • 37
  • 317
  • 271
Jason Evans
  • 28,489
  • 14
  • 89
  • 151
  • Thank you. I adjusted your solution to my needs: $(function() { $('#IBE1_IBE_NurFlug1_ddl_Abflughafen > option[value*="TR"]').hide(); }); – user168507 Jul 02 '10 at 10:23
  • @ceyago - Ahh yeah, I misread your requirement. `remove()` actually gets rid of the ` – Jason Evans Jul 02 '10 at 10:25
  • Ya its working fine. i have tried following. $("select > option[value$='TR']").remove() – Amit Soni Jul 02 '10 at 10:43
  • 1
    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. – Pherrymason Oct 28 '10 at 10:30
  • what if i have two select ? – s4suryapal Jun 02 '14 at 06:11
  • @s4suryapal I don't understand your question. – Jason Evans Jun 02 '14 at 07:29
  • If you have more than one select give them unique ids and change **select** to **#select_id** where #select_id is the id of the select you wish to work on. I hope that makes sense. – CodingInTheUK Nov 04 '17 at 18:06