Jquery 在鼠标悬停并移出时更改div元素文本的文本颜色

Jquery 在鼠标悬停并移出时更改div元素文本的文本颜色,jquery,html,css,Jquery,Html,Css,我想改变鼠标悬停和鼠标移出时的文本颜色。因为里面有很多div元素,所以它不工作。如果有任何问题,请帮助 <div class="u860" id="u860" style="top: 0px;"> <div id="u860_rtf"> <p style="text-align: left;" id="cache228"> <a class="music" href="AppLauncher_TradeSearch

我想改变鼠标悬停和鼠标移出时的文本颜色。因为里面有很多div元素,所以它不工作。如果有任何问题,请帮助

<div class="u860" id="u860" style="top: 0px;">
    <div id="u860_rtf">
        <p style="text-align: left;" id="cache228">
        <a class="music" href="AppLauncher_TradeSearch">
            <span class="test1" style="font-family: Calibri; font-size: 11px; 
                font-weight: bold; font-style: normal; text-decoration: none; 
                color: rgb(37, 80, 99);" id="cache229">Different</span>
        </a>
        </p>
    </div>
</div>


“不同”的颜色应该不断变化。

在这些情况下,最好的解决方案是使用CSS

.test1:hover{
    color:red !important;
} 
演示 不太好的做法是添加一个类,如:

$('.test1').hover(function () {
    $(this).addClass('newColor');
},
function () {
    $(this).removeClass('newColor');
});
演示

最后一个选择是:

$('.test1').hover(function () {
    $(this).css('color', 'red');
},
function () {
    $(this).css('color', 'rgb(37, 80, 99)');
});
演示

尝试以下css:

.u860:hover a, .u860:hover span {
    color:red !important;
}
您正在span中使用样式,因此必须使用!重要的

试试这个:

  $(".u860").mouseover(function(){
    $(".u860").css("background-color","cyan");
  });$(".u860").mouseout(function(){
    $(".u860").css("background-color","gray");
  });

嗨,Hmnshu,我没有看到悬停css的代码。。 试试这个

 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <style>
   span{
        font-family: Calibri; 
        font-size: 11px; 
        font-weight: bold; 
        font-style: normal; 
        text-decoration: none; 
        color: rgb(37, 80, 99);
       }
  span:hover{
       color: rgb(0, 0, 0);
       }
 </style>
 </head>
 <body>
 <div class="u860" id="u860" style="top: 0px;">
  <div id="u860_rtf">
   <p style="text-align: left;" id="cache228">
    <a class="music" href="AppLauncher_TradeSearch">
      <span class="test1"  id="cache229">Different</span>
    </a>
   </p>
 </div>
</div>
</body>
</html>

跨度{
字体系列:Calibri;
字体大小:11px;
字体大小:粗体;
字体风格:普通;
文字装饰:无;
颜色:rgb(37,80,99);
}
跨度:悬停{
颜色:rgb(0,0,0);
}


分享您已经尝试过的内容?悬停在要更改颜色的元素上时,确实需要jQuery for
:hover
?:O@ArunPJohny close如果我编写了一个非常混乱的长jQuery脚本,并给他留下了这个答案,人们会生气吗。。。。只是因为它很有趣:我在MouseOver事件中尝试过,但似乎不起作用。CSS足以改变上面的文本颜色吗?我的答案回答了你的问题吗?只是出于好奇,你能让它在没有CSS的情况下工作吗!重要事项?致:内森·李。我想你得用!重要的是,如果你在标签中使用styl atribute,它比css文件中的atribute更重要,这就是为什么要使用styl atribute!对于本例中的span元素很重要。TO:Hmnshu,我在IE8(windows 7)中尝试了它,它可以工作,但您使用什么作为操作系统?