过滤选择器first与子元素过滤选择器first-child的区别

1、表格代码如下:

<table id="table">
            <tr>
                <td>id</td>
                <td>name</td>
            </tr>
            <tr>
                <td>1</td>
                <td>aaa</td>
            </tr>
            <tr>
                <td>2</td>
                <td>bbb</td>
            </tr>
            <tr>
                <td>3</td>
                <td>ccc</td>
            </tr>
        </table>

2、表格显示如下:

idname
1aaa
2bbb
3ccc

3、分析first和first-child

过滤选择器first

首先找到id为t2的元素,再查找下面的子元素tr,从第一个tr元素开始查找子元素:第一个td,找到以后停止

$("#t2 tr td:first").css("background","red");

子元素过滤选择器first-child

首先找到id为t2的元素,再查找下面的子元素tr,然后查找每一个tr下边的第一个td元素。

$("#t2 tr td:first-child").css("background","red");

转载于:https://www.cnblogs.com/lyajs/p/5974689.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值