我想在鼠标悬停和鼠标移出时更改文本颜色。由于内部有许多 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;
}
演示 here
不太好的是添加一个类,比如:
$('.test1').hover(function () {
$(this).addClass('newColor');
},
function () {
$(this).removeClass('newColor');
});
演示 here
最后一个选项:
$('.test1').hover(function () {
$(this).css('color', 'red');
},
function () {
$(this).css('color', 'rgb(37, 80, 99)');
});
演示 here
关于jquery - 在鼠标悬停和鼠标移出时更改 div 元素文本的文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19312325/