Omiod Omiod - 5 months ago 10
jQuery Question

Selecting the first "n" items with jQuery

With Jquery, I need to select just the first "n" items from the page, for example the first 20 links instead of selecting all of them with the usual

$("a")


Sounds simple but the jQuery manual has no evidence of something like this.

Answer

You probably want to read up on slice. Your code will look something like this:

$("a").slice(0,20)