简体   繁体   English

处理tr的子元素不起作用

[英]Manipulating tr's child elements not working

I just got stuck again, perhaps someone else can spot the problem easier. 我只是再次陷入困境,也许其他人可以更轻松地发现问题。 The 1st tr's children (such as table cells) don't change background on hovering with this code: 第一个tr的子代(例如表格单元格)在使用以下代码进行悬停时不会更改背景:

$("#target tr:eq(1).find("*")").hover(function(){
        $(this).css("background", "#fff"); 
        })


<table id="target">
<tr><td\>
content 
</td></tr>
<tr><td\>
content 
</td></tr>
</table>

Is it the quotes? 是引号吗?

.find() 。找()

$("#target tr:eq(1)").find("*").hover(function () {
                    //^^ move find outside the seletor
    $(this).css("background", "#fff");
});

Demo 演示

:eq() index starts from 0 if you want 1st tr us .eq(0) :eq()索引从0开始,如果您想进行.eq(0)


Get back old color 找回旧颜色

Demo 演示

 $("#target tr:eq(1)").find("*").hover(function () { $(this).css("background", "#fff"); },function(){ $(this).css("background", "blue"); //get old color back }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 操纵 <td> 在不同的 <tr> 的 - Manipulating <td>'s within different <tr>'s js .off()没有工作 <tr> 分子 - js .off() is not working on <tr> elements 帮助使用jQuery处理子元素/父元素 - Help with manipulating child/parent elements with jQuery 通过JS / jQuery访问和操纵DOM中的子元素 - Accessing and manipulating child elements in DOM by JS/jQuery 如何处理点击 a 但不点击子元素? - How to handle a click on a <tr> but not on the child elements? 我需要隐藏“tr”元素的CSS规则,其子元素“td”具有带有空值属性的子“输入”元素? - What CSS rule do I need to hide “tr” elements whose children “td”'s have child “input” elements with empty value attributes? 在 Angular 中操作组件的 DOM 元素 - Manipulating a component's DOM elements in Angular 第一次单击在 javascript 中无法用于操作 DOM 元素 - First click is not working in javascript for manipulating DOM elements 在JQuery的dblclick()侦听器中 <tr> ,如何获取所有孩子的内容 <td> 元素以及所有内容 <td> 在表格标题行中? - In a JQuery dblclick() listener of <tr>, how to get contents of all child <td> elements, as well as the contents of all <td>'s in table header row? 木偶:按顺序操纵页面的DIV / html元素? - Puppeteer: manipulating page's DIV's/html elements in order?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM