JQuery 后代元素与子元素的差别

后代元素即层级比当前元素低的所有元素,包括子元素

子元素即层级比当前元素低一级的直接元素

参见 http://blog.sina.com.cn/s/blog_775da6710100vzbr.html

<div>This is <strong>very</strong> important.</div>

<div>This is <em>really <strong>very</strong></em> important.</div>

 

以上是html。运行后在浏览器里是看到

 

This is very important.
This is really very important.
 
 

这样的样式,为了容易看到效果,我们不妨就尝试用添加css颜色来试一下

 

如果运行$("div strong").css("color","red");就是把div的后代元素strong变为红色。运行后是

 

This is very important.
This is really very important.
 
 如果运行$("div>strong").css("color","blue");就是把div的子元素strong变为蓝色。运行后是
 
This is very important.
This is really very important.

转载于:https://www.cnblogs.com/Gravin-Gu/p/3421868.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值