Quick jQuery snippet to select first x number of elements. You can also use the jQuery .slice() function which can chop up element groups into a range for you with a combination of .get(); |
$("a").slice(0,20) |
lso you can use lt pseudo selector: This matches the elements before the nth one (the nth element excluded). Numbering starts from 0 |
$(“a:lt(n)”) |
Because :lt() is a jQuery extension and not part of the CSS specification, queries using :lt() cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. For better performance in modern browsers, use $("your-pure-css-selector").slice(0, index) instead |
Showing posts with label slice. Show all posts
Showing posts with label slice. Show all posts
Friday, March 30, 2018
jquery select first x number of elements | Selecting the first “n” items with jQuery
Subscribe to:
Posts (Atom)