Juliver Galleto
Juliver Galleto

Reputation: 9037

add a start div tag to the element and end div tag to another element

I have this html structure (refer below)

<div class="pagination_info"></div>
<div class="pagination_numbers"></div>

Now, what I want is to add a start div tag before the .pagination_info div and add end div tag after the .pagination_numbers div so the expected output must be (refer below)

<div class="pagination_wrapper">
    <div class="pagination_info"></div>
    <div class="pagination_numbers"></div>
</div>

what I tried so far is (refer below)

$('.pagination_info').before('<div class="pagination_wrapper">');
$('.pagination_numbers').after('</div>');

so supposedly, what im trying to achieve is to wrap the .pagination_info div and .pagination_numbers with a parent div that has a class name "pagination_wrapper" but sadly unsuccessful yet. Any help, suggestion, recommendation, ideas, clues to make this work will be greatly appreciated. Thank you.

Upvotes: 3

Views: 733

Answers (2)

Brijesh Bhatt
Brijesh Bhatt

Reputation: 3830

.wrapAll() will wrap the two div's around the new div:

$(".pagination_info, .pagination_numbers").wrapAll("<div class='pagination_wrapper'>");

FIDDLE

Upvotes: 6

CodingIntrigue
CodingIntrigue

Reputation: 78525

jQuery has a wrapAll method:

$(".pagination_info, .pagination_numbers").wrapAll("<div class=\"pagination_wrapper\">");

Working Example

Upvotes: 8

Related Questions