ITeye博客

Difference between jQuery wrap and wrapAll

何不笑 · 2013-04-16 20:15 · JQuery · Web前端 · Markdown

Notice the difference in the descriptions:

.wrap(): Wrap an HTML structure around each element in the set of matched elements. 
.wrapAll(): Wrap an HTML structure around all elements in the set of matched elements.
.wrap() wraps every element individually, but .wrapAll() wraps all of them as a group.

 For example:

<div class="foo"></div>
<div class="foo"></div>
<div class="foo"></div>

 With $('.foo').wrap('<div class="bar" />');, this happens:

<div class="bar"><div class="foo"></div></div>
<div class="bar"><div class="foo"></div></div>
<div class="bar"><div class="foo"></div></div>

 But with $('.foo').wrapAll('<div class="bar" />');, this happens:

<div class="bar">
  <div class="foo"></div>
  <div class="foo"></div>
  <div class="foo"></div>
</div>

 from :http://stackoverflow.com/questions/11946379/difference-between-jquery-wrap-and-wrapall

 learn wrapInner:  http://api.jquery.com/wrapInner/

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。