我想在.left
之前用div附加div。它必须在.right
之后关闭。我尝试过如下,但它自动关闭在同一行。
我也试过wrap()但没有运气。
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'>" );
答案 0 :(得分:3)
答案 1 :(得分:2)
$('.tp').wrapAll('<div class="group" />')
&#13;
<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>
&#13;