soccer7
soccer7

Reputation: 4025

Wrap HTML Element With Jquery

I have following Code in HTML

<div class="newloop_11"></div>
<div class="newloop_12"></div>
<div class="newloop_13"></div>
<div class="newloop_14"></div>
<div class="newloop_15"></div>
<div class="newloop_16"></div>

And When i call a ajax request on any event 

i got following HTML 

<div class="replacewith_11 textme loop" id="test_1">
//lotsof content

</div>
<div class="replacewith_12 textme loop" id="test_2">
//lotsof content

</div>
<div class="replacewith_13 textme loop" id="test_3">
//lotsof content

</div>

Now I want to wrap ajax html with previous HTML

if their value is matched

Expectd out like this

<div class="replacewith_11 textme loop" id="test_1">
//lotsof content

</div>
<div class="replacewith_12 textme loop" id="test_2">
//lotsof content

</div>
<div class="replacewith_13 textme loop" id="test_3">
//lotsof content

</div>
<div class="newloop_14"></div>
<div class="newloop_15"></div>
<div class="newloop_16"></div>

How to do this in Jquery.

I tried InnerHTML, append, html method, but i have no idea how to do this

Any Help will be apprecaited

Thanks

Upvotes: 2

Views: 82

Answers (1)

Alex Char
Alex Char

Reputation: 33238

One solution is to use jquery .after() inside success of your ajax call:

$(".newloop_13").after("<div>your ajax result</div>");

See an example here: fiddle

Upvotes: 1

Related Questions