javascript - $(this).children() 不工作

标签 javascript jquery html css

我有以下代码:

<tr><td class="style3">test</td></tr>

$("tr").hover(
  function () {
    $(this).css("background-color","#d9e8cd");
    $(this).css("font-weight","bold");
    $(this).children().css("color","#222222 !important");
  }, 
  function () {
    $(this).css("background-color","");
    $(this).css("font-weight","");
    $(this).children().css("color","#4b4a4a");
  }
);

问题是文本颜色不会改变,我尝试指定 tr 但它不起作用所以我假设以 td 为目标会使其工作,因为指定颜色的 style3 类。

我怎样才能使鼠标悬停在 tr 上时文本的颜色发生变化?

这是一个在线演示 http://jsfiddle.net/B7dMd/

最佳答案

jQuery CSS 不支持重要语法。如果你真的需要添加 "!important"你可能想试试 CSS DOM cssText:

$(this).children().css('cssText', 'color:#222222 !important');

要指出的是 - 在大多数情况下,没有理由应该在内联样式中添加 !important,因为内联样式具有高优先级,您只需要这样做来覆盖另一个 !important规则。

关于javascript - $(this).children() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14062555/

相关文章:

javascript - jquery函数改变html标签

javascript - Wordpress - Media Master 主题中的损坏菜单

html - 如何放置页面的按钮(在顶部菜单栏中)特定图像?

javascript - 自定义 jQuery 验证方法

javascript 传输和元素从 1 个 div 到另一个 div

javascript - ASP Net MVC 从 JS 错误调用 Controller 中的函数

javascript - 如何获得与 CSS 媒体查询检查相同的宽度

jquery - 使用 jQuery 更改图像?

javascript - 检索每个元素具有最高日期的唯一元素

javascript - 强制 AngularJS 在 html 端重新加载更新的值