Select last 5 elements with jQuery

前端 未结 3 1776
小鲜肉
小鲜肉 2020-12-04 09:32

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

3条回答
  •  暖寄归人
    2020-12-04 09:59

    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)+")");
    

提交回复
热议问题