views:

191

answers:

2

Is it possible to select the last 5 child divs of an element?

+5  A: 

Sure, you could use the .length property of a selector to get the count, and then use the :gt(n) selector to get the last 5.

var o = $("div.container > div:gt("+($("div.container > div").length-5)+")");
Jonathan Sampson
+11  A: 

Yes, you can get the div elements, and then use the slice method to get the last five:

var e = $('#someelement > div').slice(-5);
Guffa
+1 Very clean and simple.
Jonathan Sampson