开发者

jquery: Finding the last child from a selector

For example, I've got a selector here

var $myNeeds = $('.history');

This selector would have multiple divs inside, and now I want to get th开发者_C百科e last child from it, how to do this?

I tried $myNeeds.last(), this won't work!


Alternatively....

$myNeeds.find('>:last-child')

jsFiddle.


You're almost there...

$myNeeds.children().last()

The last method gets the last element in your set.
You want the last child of your set, so you need to get a new set with the children.

You could also write

$('.history > :last-child')

or

$myNeeds.children(":last")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜