O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Slicing Up Selector Results

$("tr").slice(2,5);   //selects the <tr> elements between 2 and 4 inclusive $("p").slice(1,-1);   //selects all <p> elments except the first and last

The .slice(start, [end]) method removes elements before index start and after index end and returns only the items in between. This allows you to break large selections into smaller chunks. The indexes are zero based. A negative end indicates the offset from the end of the list, where –1 is the last element and –2 is the second to the last element.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required