I want to append div with class before the .left
. Its must be close after the .right
. I have tried like below but its automatically close in same line.
I also tried wrap() but no luck.
HTML
<!-- <div class="group"> -->
<div class="tp left arrow">Left</div>
<div class="tp bullets">
<div class="round">1</div>
<div class="round">2</div>
<div class="round">3</div>
<div class="round">4</div>
<div class="round">5</div>
</div>
<div class="tp right arrow">right</div>
<!-- </div> -->
JS
$( ".left" ).before( "<div class='group'>" );
$( ".right" ).after( "</div'>" );
You can use wrapAll()
method for that
$(".left,.bullets,.right").wrapAll("<div class='group'></div>")
$('.tp').wrapAll('<div class="group" />')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="tp left arrow">Left</div> <div class="tp bullets"><div class="round">1</div><div class="round">2</div><div class="round">3</div><div class="round">4</div><div class="round">5</div></div> <div class="tp right arrow">right</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.