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

后代元素即层级比当前元素低的全部元素,包括子元素css

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

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

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

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

 

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

 

This is very important.
This is really very important.
 
 

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

 

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

 

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.
相关文章
相关标签/搜索