Is it possible to select the last 5 child divs of an element?
The :last selector selects the last element. Note: This selector can only select one single element. Use the :last-child selector to select more than one element (one for each parent). This is mostly used together with another selector to select the last element in a group (like in the example above).
Approach 2: Use $('table tr:last') jQuery Selector to find the last element of the table. The 'table' in query looks for the table element then 'tr' is looking for all the rows in the table element and ':last' is looking for the last table row of the table.
You need to use "nth-last-child(2)" of jquery, this selects the second last element.
Definition and UsageThe :last-child selector selects all elements that are the last child of their parent. Tip: Use the :first-child selector to select elements that are the first child of their parent.
Yes, you can get the div elements, and then use the slice
method to get the last five:
var e = $('#someelement > div').slice(-5);
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)+")");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With