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")
精彩评论