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.
相關文章
相關標籤/搜索