jquery子元素筛选

jQuery( ":first-child" )

选择所有父级元素下的第一个子元素。

eg:

$("div span:first-child").css("color","green");

 

jQuery( ":first-of-type" )

选择所有相同的元素名称的第一个兄弟元素。

eg:

$("span:first-of-type").css("color","red");

 

jQuery( ":last-child" )

选择所有父级元素下的最后一个子元素。

eg:

$("div:last-child").css("color","pink");

 

jQuery( ":last-of-type" )

选择的所有元素之间具有相同元素名称的最后一个兄弟元素

eg:

$("span:last-of-type").css("color","yellow");

 

jQuery( ":nth-child(index/even/odd/equation)" )

选择的他们所有父元素的第n个子元素(index: 每个相匹配子元素的索引值,从1开始,也可以是字符串 even 或 odd,或一个方程式( 例如:nth-child(even):nth-child(4n) ))

 

posted on 2016-08-29 00:16  ranyinchun  阅读(312)  评论(0编辑  收藏  举报