Programming Tips - How can I show/hide a select's options ?

Date: 2010sep2
Language: javaScript

Q.  How can I show/hide a <select>'s <option>s ?

A.  With Firefox you can do:

for (i = 0; i < objSelect.options.length; i++) { if (isWantIt(objSelect.options[i].value)) { objSelect.options[i].style.display = 'block'; } else { objSelect.options[i].style.display = 'none'; } }
But sadly, that doesn't work in IE. Changing the className doesn't work either. With IE you have to change all the options!