Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
54
rated 0 times [  59] [ 5]  / answers: 1 / hits: 63472  / 15 Years ago, wed, february 24, 2010, 12:00:00

ok, heres some sample code that demonstrates the problem.
if i click the button in firefox, the first option disappears.
if i click the button in chrome, nothing happens, or rather if i inspect the first option, it does have the attribute style='display:none' but the option itself on the html page is not hidden.



<form>
<select>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<input type=button onclick=document.getElementsByTagName('option')[0].style.display='none' value=hide option 1>
</form>


why doesn't this work in chrome?


More From » firefox

 Answers
9

The workaround is to remove the option elements in response to your event and add them back if and when they are needed. IIRC, IE will not allow you to set the display to none on option elements. I would advise storing the removed elements in an array so that you can easily add them back in.


[#97503] Friday, February 19, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
allanw

Total Points: 421
Total Questions: 132
Total Answers: 102

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
;