使用jQuery更改li的背景颜色 [英] change background color of li using jquery

查看:840
本文介绍了使用jQuery更改li的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在鼠标悬停时更改包含锚点的li的颜色,我这样做

I want to change the color of li which contains anchor when the mouse go over it, I make like this

 <ul id="SonsItemList">
     <li class="sonItem"><a id="son" href="#" >son 1</a></li>
      <li class="sonItem"><a id="son" href="#" >son 2</a></li>        
 </ul>

jquery是

 $(document).ready(function(){
            $("a#son").hover(function(){
               $("li.sonItem").css("background-color","black");  // it make all li background => black


        });

我只想让慕斯走过去改变背景,我该怎么做? });

I just want the li that the mous go over to change it's background, how can I make it ? });

推荐答案

您根本不需要任何JavaScript.您可以使用CSS:

You don't need any JavaScript at all. You can use CSS:

li.sonItem:hover 
{
    background-color: black;
}

这篇关于使用jQuery更改li的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆