jQuery slice()Method
Examples
Select <p> elements starting from the <p> element with index number 2:
Try it Yourself »
Definition and Usage
The slice() method selects a subset of elements based on index.
A subset is a set that is part of a larger set.
This method is used to limit the selection of elements in a collection by specifying a start point and an end point:startThe parameter is the start index for creating the subset (starting from 0),stopThe parameter is an optional end point.
Syntax
| Parameter | Description |
|---|---|
| start | Required. Specifies the position from which to start selecting elements. The index number starts from 0. Note:If it is a negative number, it indicates that elements are selected from the end of the selected elements, rather than from the beginning. |
| stop | Optional. Specifies the position to stop selecting elements. If omitted, the selection range ends at the end of the collection. The index number starts from 0. Note:If it is a negative number, it indicates that elements are selected from the end of the selected elements, rather than from the beginning. |
More Examples
start and stop
How to use these two parameters to select <p> elements from the start point to the end point.
Using negative numbers
Use negative numbers to select <p> elements starting from the end, rather than from the beginning.
Using negative numbers for both parameters
Use negative start and stop parameters to select <p> elements from the end.
Other extensions
jQuery Traversal Methods