juqery 学习之四 筛选过滤

2020-05-23 06:26:19易采站长站整理


HTML 代码:


<p>Hello</p><p>cruel</p><p>World</p>

jQuery 代码:


$(“p”).slice(1).wrapInner(“<b></b>”);

结果:


[ <p><b>cruel</b></p>, <p><b>World</b></p> ]

Selects all paragraphs, then slices the selection to include only the third element.


HTML 代码:


<p>Hello</p><p>cruel</p><p>World</p>

jQuery 代码:


$(“p”).slice(-1).wrapInner(“<b></b>”);

结果:


[ <p><b>World</b></p> ]