开发者

returning new set from jquery's .wrap()

jQuery's .wrap() method returns the original set of elements for chaining purposes.

What is the most elegant way to return the original set of elements + the wrapped el开发者_如何学运维ements instead?


If I understand you correctly, you'll need parent() and andSelf().

  • parent() will retrieve the parent for each element in the collection.
  • andSelf() will add the former collection to the new collection.

$("div.elements-to-wrap").wrap('<div class="wrapper" />').parent().andSelf();

Now, you have a new collection that contains both div.elements-to-wrap and all the div.wrapper that wrap the former elements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜