最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Change option background color on hover? - Stack Overflow

programmeradmin0浏览0评论

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");
}); 

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");
}); 
Share Improve this question asked Mar 11, 2012 at 2:48 user198989user198989 4,66520 gold badges68 silver badges95 bronze badges 4
  • Even if it could be done, you'd want to do this with CSS, not JavaScript. – Dagg Nabbit Commented Mar 11, 2012 at 3:27
  • i think this may solve your question stackoverflow./questions/2402146/… – Angel Commented Aug 10, 2014 at 15:05
  • take a look at this article : jQuery Select CSS Style – Farshad Commented Sep 1, 2014 at 6:01
  • possible duplicate of Change Select List Option background colour on hover – doppelgreener Commented May 1, 2015 at 7:22
Add a ment  | 

3 Answers 3

Reset to default 1

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

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.

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

发布评论

评论列表(0)

  1. 暂无评论