是否可以选择一个元素的最后5个子 div?
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.
.length
:gt(n)
var o = $("div.container > div:gt("+($("div.container > div").length-5)+")");
Yes, you can get the div elements, and then use the slice method to get the last five:
slice
var e = $('#someelement > div').slice(-5);
As of jQuery 1.8, you can use a negative value in the :gt() pseudo selector.
:gt()
Reference: https://api.jquery.com/gt-selector.
e.g.
var e = $('#someelement > div:gt(-6)');
JSFiddle: https://jsfiddle.net/TrueBlueAussie/g4drety2/3/
Notes:
n+1
.slice(-5)
:gt