JQuery

jQuery filter-slice(start, [end])

jQuery filter-slice(start, [end]), someone asked me to explain?

Overview

Pick a matching subset

Similar to the original slice method

parameter

startIntegerV1.1.4

Start selecting the location of the subset. The first element is 0. If it is a negative number, it can be selected from the end of the collection.

than Integer V1.1.4

End the selection of your own location, if not specified, it is the end of itself.

Example

description:

Select the first p element

HTML code:
<p>Hello</p><p>cruel</p><p>World</p>
jQuery code:
 $("p").slice(0, 1).wrapInner("<b></b>");
result:
[ <p><b>Hello</b></p> ]

description:

Select the first two p elements

HTML code:
<p>Hello</p><p>cruel</p><p>World</p>
jQuery code:
$("p").slice(0, 2).wrapInner("<b></b>");
result:
[ <p><b>Hello</b></p>,<p><b>cruel</b></p> ]

description:

Select only the second p element

HTML code:
 <p>Hello</p><p>cruel</p><p>World</p>
jQuery code:
 $("p").slice(1, 2).wrapInner("<b></b>");
result:
[ <p><b>cruel</b></p> ]

description:

Select only the second third p element

HTML code:
<p>Hello</p><p>cruel</p><p>World</p>
jQuery code:
$("p").slice(1).wrapInner("<b></b>");
result:
[ <p><b>cruel</b></p>, <p><b>World</b></p> ]

description:

Select the last p element

HTML code:
<p>Hello</p><p>cruel</p><p>World</p>
jQuery code:
$("p").slice(-1).wrapInner("<b></b>");
result:
[ <p><b>World</b></p> ]

 

 

 

 

Post your comments / questions