wrapInner() of body until a specified element

Peter Featherstone

Using the 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 the whole of the body section easily using $('body').wrapInner('<div class="content"></div>'); but how can I wrap the body content up until my wrap-until div element, so it 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: The content inside the body will always be different but the #wrap-until element will always be available.

Rory McCrossan

You can grab all the required elements and use not() to exclude the wrap-until element then wrapAll(), like this:

$('body > *').not('#wrap-until').wrapAll('<div class="content"></div>');

Working example

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

wrapInner doesn't add children to wrapping element in DOM

From Dev

Seconds Until a Specified Day of the Week

From Dev

Wait until element is not present

From Dev

Block until element is available

From Dev

PHP `time_sleep_until()` does not sleep until specified time

From Dev

Non-interactive fixup until specified hash

From Dev

Run .py file until specified line number

From Dev

Calculating days left until the next specified day

From Dev

Repeat terminal command until specified output

From Dev

Calculating days left until the next specified day

From Dev

How to append element to body?

From Dev

pseudo element body border

From Dev

Height of <body> element in HTML

From Dev

Hiding element on body click

From Dev

Wait until particular element to disappear

From Dev

Center element until it meets an obstacle

From Dev

How to wait until element present?

From Dev

Allow scrolling until last element

From Dev

Wait until an element is active, selenium

From Dev

jQuery unwrap element until content

From Dev

Element is not displayed until click on button

From Dev

Wait for clicking until the element is rendered

From Dev

wrapInner() with href of children elements

From Dev

Wrapping contents of element until specific element

From Dev

jQuery change css on a specified element

From Dev

Unable to click on specified li element

From Dev

Get element at the specified position in arraylist

From Dev

Find Element Next to Element With Specified Text

From Dev

Select element but deselect specified child of element