slice

UK[slaɪs] 美[slaɪs]

vt. Cut into slices; cut off; divide

n. Thin slices; part; a curve ball (played due to a mistake)

vi. Slant shot

jquery slice() method syntax

Function: slice() reduces the set of matching elements to a subset of the specified index range.

Syntax: .slice(selector,end)

Parameters:

ParameterDescription
selector A 0-based integer value indicating the position where to start selecting elements. If negative, indicates the offset from the end of the collection.
endA 0-based integer value indicating the position where the selected element ends. If negative, indicates the offset from the end of the collection. If omitted, the selection ends at the end of the collection.

Description: If given a jQuery object representing a collection of DOM elements, the .slice() method constructs a new one with a subset of matching elements. jQuery object. The position of an element in the applied index parameter set; if the end parameter is omitted, all elements after index will be included in the result.

jquery slice() method example

<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
</head>

<body>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>

<script>
$("p").slice(0, 2).wrapInner("<b></b>");
</script>

</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance