I've realized that Chrome, it seems, will not allow me to hide <option>
in a <select>
. Firefox will.
I need to hide the <option>
s that match a search criteria. In the Chrome web tools I can see that they are correctly being set to display: none;
by my JavaScript, but once then <select>
menu is clicked they are shown.
How can I make these <option>
s that match my search criteria NOT show when the menu is clicked? Thanks!
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. Removing the hidden attribute makes it re-appear.
Answer: Use the CSS :hover pseudo-class If you simply want to show and hide dropdown menu on mouse hover you don't need any JavaScript. You can do this simply using the CSS display property and :hover pseudo-class.
You can hide an element in CSS using the CSS properties display: none or visibility: hidden. display: none removes the entire element from the page and mat affect the layout of the page. visibility: hidden hides the element while keeping the space the same.
For HTML5, you can use the 'hidden' attribute.
<option hidden>Hidden option</option>
It is not supported by IE < 11. But if you need only to hide a few elements, maybe it would be better to just set the hidden attribute in combination with disabled in comparison to adding/removing elements or doing not semantically correct constructions.
<select> <option>Option1</option> <option>Option2</option> <option hidden>Hidden Option</option> </select>
Reference.
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