jQuery slice() method
Example
from the with index number 2
start selecting elements
element:
$("p").slice(2)
Try it »
Definition and Usage
The slice() method selects a subset of elements based on their indices.
A subset is a set that is part of a larger set.
This method is used to limit the selection of elements in a set by a start point and an end point:start parameter is the starting index for creating the subset (starting from 0),stop parameter is an optional end point.
Syntax
$(
selector
).slice(
start,stop
)
| Parameters | Description |
|---|---|
| start | Required. Specifies the position at which to start selecting elements. Index numbers start at 0. |
**注意:**如果是负数,则指示从被选元素的末端开始选取元素,而不是从头开始。 |
| stop | Optional. Specifies the position at which to stop selecting elements. If omitted, the selection range ends at the end of the set. Index numbers start at 0.
**注意:**如果是负数,则指示从被选元素的末端开始选取元素,而不是从头开始。 |
More examples
start and stop
How to use these two parameters to select the from the start point to the end point
.
Using negative numbers
Use negative numbers to start selecting from the end
elements, rather than from the beginning.
Using two parameters with negative numbers
Use negative start and stop parameters to start selecting from the end
.
jQuery Traversal Methods