4

How can I change the background color when user hovers it ? I have tried this but it's not working.

<select>
<option>bmw</option>
<option>audi</option>
<option>mercedes</option>
</select>



$('option').hover(function(){
$(this).css("background-color","#FFFFCC");
}); 
user198989
  • 4,574
  • 19
  • 66
  • 95
  • Even if it could be done, you'd want to do this with CSS, not JavaScript. – Dagg Nabbit Mar 11 '12 at 03:27
  • i think this may solve your question http://stackoverflow.com/questions/2402146/html-select-selected-option-background-color-css-style – Angel Aug 10 '14 at 15:05
  • take a look at this article : [jQuery Select CSS Style](http://www.1stwebmagazine.com/jquery-select-css-style) – Farshad Sep 01 '14 at 06:01
  • possible duplicate of [Change Select List Option background colour on hover](http://stackoverflow.com/questions/10484053/change-select-list-option-background-colour-on-hover) – doppelgreener May 01 '15 at 07:22

3 Answers3

1

You cannot use option in this way. The best solution would be styling something similar with <ul> and <li> and interacting with JS.

David Houde
  • 4,835
  • 1
  • 20
  • 29
0

hover event can not be bound to an option tag. I'll update this post if I find the documentation or proof that says so. In my experience, this cannot be done.

shanabus
  • 12,989
  • 6
  • 52
  • 78
0

Since you already use jQuery, there is a pretty nice plugin - image-dropdown + demo from the makers.

Bakudan
  • 19,134
  • 9
  • 53
  • 73