jquery - 在鼠标悬停和鼠标移出时更改 div 元素文本的文本颜色

标签 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">
            <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/

相关文章:

javascript - 简单的 JS 刷新 Div 不工作

php - 如何在 WordPress 中的特定帖子类型上导入 CSS 文件

html - 使内部 html 内容向下跳转而不是外部 html 内容

CSS:创建带纹理的背景

javascript - Jquery 用户界面对话框

javascript - 动画时图像叠加弹出

javascript - Jquery 删除类正在重新应用该类

javascript - 不要在点击链接时发送 GET 请求

android - 悬停效果在 Android 浏览器中不起作用

html - 无法在输入文本字段中键入