Questions tagged [wrapall]

A jQuery method that wraps an HTML structure around all elements in the set of matched elements.

.wrapAll() is a jQuery method. It is used to:

wrap an HTML structure around all elements in the set of matched elements
api.jquery.com

Consider the following HTML:

<div class="container">
  <div class="inner">Hello</div>
  <div class="inner">Goodbye</div>
</div>

Using .wrapAll(), we can insert an HTML structure around the inner <div> elements like so:

$( ".inner" ).wrapAll( "<div class='new' />");

The new <div> element is created on the fly and added to the DOM. The result is a new <div> wrapped around all matched elements:

<div class="container">
  <div class="new">
    <div class="inner">Hello</div>
    <div class="inner">Goodbye</div>
  </div>
</div> 
79 questions
88
votes
6 answers

Wrap every 3 divs in a div

Is it possible to use nth-child selectors to wrap 3 divs using .wrapAll? I can't seem to work out the correct equation. so...
csbourne
  • 957
  • 1
  • 8
  • 10
26
votes
4 answers

jQuery append text inside of an existing paragraph tag

I am trying to add additional text to the end of a paragraph using jQuery. My thought was to produce a structure like this: Judging by my answers I will clarify. I need to create this structure first. And this is the part that I find difficult, not…
sage88
  • 4,104
  • 4
  • 31
  • 41
25
votes
3 answers

How to get the wrapper element created with "wrapAll()"?

Consider the following code: (live example here) $(function() { var wrapper = $("
"); $(".a").wrapAll(wrapper); wrapper.css("border", "5px solid black"); // Doesn't work }); .wrapper { background-color:…
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
7
votes
5 answers

Wrap multiple div elements on same class

I would like to use jQuery to wrap sets of class elements in a div but can't find the solution. HTML:
content
content
content
Matthias O.
  • 192
  • 1
  • 2
  • 13
6
votes
2 answers

jQuery nextUntil include text nodes

I'm using nextUntil method to get all stuff between two elements. But this method does not include text nodes to output. It gives an array like [
,
,
]. How can I get all stuff including text nodes? This is the HTML code: $('.content…
Dorukcan Kişin
  • 1,121
  • 2
  • 14
  • 29
5
votes
2 answers

How can I group jQuery objects without using selectors?

The jQuery.wrapAll function takes a dom subtree and wraps it around a jQuery object. I want to do that but without aquiring the target jQuery object via selector: I have a bunch of references to jQuery wrapped DOM elements and I want to apply…
Paralife
  • 6,116
  • 8
  • 38
  • 64
5
votes
3 answers

Looking for a jQuery function similar to wrapAll that will only wrap consecutive elements

Is there a version of wrapAll that will only wrap consecutive elements? So this:

foo

foo

bar

foo

turns into this:

foo

foo

bar

foo

When this is…
mattalxndr
  • 9,143
  • 8
  • 56
  • 87
5
votes
2 answers

jQuery add first part of div, then add last part of div seperatley

I'm trying to wrap the following prices and text together, all in one div. This is what I have:
ToddN
  • 2,901
  • 14
  • 56
  • 96
5
votes
2 answers

.slice and .wrapall

I'm using a bit of code suggested by a member on stackoverflow and adapted by me to wrap every 3 list items as part of a mega menu. The code is: var lis = $("ul > li"); for(var i = 0; i < ls.length; i+=3) { lis.slice(i, i+3).wrapAll("
csbourne
  • 957
  • 1
  • 8
  • 10
5
votes
2 answers

Wrapping range of children elements in a div

I'm trying to wrap a range of children elements in div in order to manipulate them in groups; trying to position each group in a different place. The scenario is that I have a list randomly generating li tags and no matter how many appear I need…
Zack Brady
  • 110
  • 2
  • 11
4
votes
3 answers

Wrapping consecutive list items in separate groups using jQuery

I have an unordered list exported by a CMS and need to identify
  • elements that have the class .sub and wrap them in a
      . I have tried the wrapAll() method but that finds all
    • elements and wraps them in one
        . I need it to…
  • Lucas JD
    • 121
    • 1
    • 1
    • 6
    4
    votes
    1 answer

    Split list of elements into groups

    I would like to split list of elements into groups of 4 except one before last that should contain 2 elements only. x x x x x x x x x x x x x x x x x x x    x x x x x x    x This will slice into groups of 4 el.: for ( var i = 0; i < $(".el").length;…
    art0076
    • 57
    • 7
    4
    votes
    1 answer

    WrapAll() on multiple classes with multiple appearance

    Lets say this is my HTML
    4
    votes
    2 answers

    Wrap HTML with DIV until next H3

    I have the following HTML structure: $('#subgroup a').nextUntil('h3').wrapAll('
    ');

    Group name #1

    rebellion
    • 6,628
    • 11
    • 48
    • 79
    4
    votes
    2 answers

    How can I wrap each element and all its siblings before the next occurrence of the same element?

    I've got some markup that's similar to the following:

    A Heading

    Here is a paragraph.

    • First
    • Second
    Here's some other block-level element

    The Wrapping Should…

    Curtis Blackwell
    • 3,130
    • 3
    • 27
    • 45
    1
    2 3 4 5 6