jquery - wrapInner() of body until a specified element -
using below html:
<body> <h1>foo</h1> <div>a</div> <div>b</div> <h4>bar</h4> <div>c</div> <div id="wrap-until"></div> </body> i can wrap whole of body section using $('body').wrapinner('<div class="content"></div>'); but how can wrap body content until wrap-until div element, looks like:
<body> <div class="content"> <h1>foo</h1> <div>a</div> <div>b</div> <h4>bar</h4> <div>c</div> </div> <div id="wrap-until"></div> </body> note: content inside body different #wrap-until element available.
you can grab required elements , use not() exclude wrap-until element wrapall(), this:
$('body > *').not('#wrap-until').wrapall('<div class="content"></div>');
Comments
Post a Comment