Reputation: 457
I have two block with the same classes in which the content - is the title and description. How to collect all the titles into one div and placed above description.
What I have now
<div class="div">
<div class="title"></div>
<p>some text</p>
<div class="title"></div>
<p>some text</p>
<div class="title"></div>
<p>some text</p>
<div class="title"></div>
</div>
<div class="div">
<div class="title"></div>
<p>some text</p>
<div class="title"></div>
<p>some text</p>
<div class="title"></div>
<p>some text</p>
<div class="title"></div>
</div>
want this result -----------------------------------------------
<div class="div">
<div class="container-for-title">
<div class="title"></div>
<div class="title"></div>
<div class="title"></div>
<div class="title"></div>
</div>
<p>some text</p>
<p>some text</p>
<p>some text</p>
<p>some text</p>
</div>
<div class="div">
<div class="container-for-title">
<div class="title"></div>
<div class="title"></div>
<div class="title"></div>
<div class="title"></div>
</div>
<p>some text</p>
<p>some text</p>
<p>some text</p>
<p>some text</p>
</div>
Upvotes: 2
Views: 33
Reputation: 67217
You can do it by using wrapAll()
,
$(".div").each(function() {
$(".title", this).wrapAll($("<div>", {
class: "container-for-title"
}));
});
Upvotes: 2