html - Create a <div> inside a <div> and append some contents on that <div> created jQuery -
i customizing plugin , plugin has own html structure. problem want make contents put in 1 <div>
. i'll explain more after code.
here's plugin html code:
<div class="section"> <div class="panel"> <h2>test</h2> <div class="box"> content 1 </div> <div class="box"> content 1 </div> <div class="box"> content 1 </div> </div> <div class="panel"> <h2>test 2</h2> <div class="box"> content 2 </div> <div class="box"> content 2 </div> <div class="box"> content 2 </div> </div> <div class="panel"> <h2>test 3</h2> <div class="box"> content 3 </div> <div class="box"> content 3 </div> <div class="box"> content 3 </div> </div> </div>
so here's want. want .box
put in 1 <div>
.
here's desired html code:
<div class="section"> <div class="panel"> <h2>test</h2> <div class="wrapper-box"> <div class="box"> content 1 </div> <div class="box"> content 1 </div> <div class="box"> content 1 </div> </div> </div> <div class="panel"> <h2>test 2</h2> <div class="wrapper-box"> <div class="box"> content 2 </div> <div class="box"> content 2 </div> <div class="box"> content 2 </div> </div> </div> <div class="panel"> <h2>test 3</h2> <div class="wrapper-box"> <div class="box"> content 3 </div> <div class="box"> content 3 </div> <div class="box"> content 3 </div> </div> </div> </div>
those .box
elements being wrap inside .wrapper-box
. how using jquery ? believe using append
don't know or how :) answers appreciated. thank sir/mam :)
you can iterate on each .panel
, use wrapall()
$('.panel').each(function(){ $(this).find('.box').wrapall('<div class="wrapper-box" />') });
$('.panel').each(function() { $(this).find('.box').wrapall('<div class="wrapper-box" />') })
.wrapper-box { border: 1px solid red; padding: 5px; } .box { border: 1px solid green; padding: 5px; margin-bottom: 5px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="section"> <div class="panel"> <h2>test</h2> <div class="box">content 1</div> <div class="box">content 1</div> <div class="box">content 1</div> </div> <div class="panel"> <h2>test 2</h2> <div class="box">content 2</div> <div class="box">content 2</div> <div class="box">content 2</div> </div> <div class="panel"> <h2>test 3</h2> <div class="box">content 3</div> <div class="box">content 3</div> <div class="box">content 3</div> </div> </div>
Comments
Post a Comment