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
2009-12-22 18:10:18
+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
2009-12-22 18:13:34
+1 Very clean and simple.
Jonathan Sampson
2009-12-22 18:24:23