wrapping some content except the first element

user3142695

I would like to wrap all elements of a container except the first one:

<div class="anyclass">
    <p>First</p>
    <p>Second</p>
    <ul><li>List</li></ul>
    <p>Third</p>
</div>

This should become

<div class="anyclass">
    <p>First</p>
    <div class="wrapit">
        <p>Second</p>
        <ul><li>List</li></ul>
        <p>Third</p>
    </div>
</div>

This doesn't work.

$( ".anyclass p, anyclass ul" ).wrapAll( "<div class='wrapit' />");

Also it wraps ALL elements. But I need the exception of the first element.

Update: And how can I do it the other way round? That means, just unwrapping the .wrapit-container.

DoXicK
$('.anyclass').children('p,ul').not(':first-child').wrapAll('<div class="wrapit" />');

should do the trick

unwrapping can be done by the .unwrap() function:

$('.anyclass').children('.wrapit').children().unwrap();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

wrapping some content except the first element

From Dev

Prevent content from wrapping around floated element

From Dev

Removing every child element EXCEPT first child?

From Dev

Java - Removing an element from LinkedList except first

From Dev

How to shift except in the first element in array Javascript?

From Dev

Preferred way to iterate a List except the first element

From Dev

implement code for all elements except the first element

From Dev

Contenteditable bug when wrapping some text with link element

From Dev

Why isn't my TD element wrapping around text content?

From Dev

Why isn't my TD element wrapping around text content?

From Dev

jQuery get div content text and elements except some elements

From Dev

Xpath How to get text content from childs except some tags

From Dev

javascript check if an element content some part of an array

From Dev

Hide all except first child of an element using pure css

From Dev

How to remove cloned element div except first div using jquery

From Dev

Iterating over each element of an array, except the first one

From Dev

Check if all element except the first has a certain class

From Dev

How to remove cloned element div except first div using jquery

From Dev

c++ 98, vector, remove every element except the first one

From Dev

Capitalize first letter of various tags content element

From Dev

Need an array where with first element of new array=sum of all elements except the first element-Javascript

From Dev

iterating over elements in a vector, wrapping around from the last element to the first element in a circular fashion

From Dev

LinearLayout not wrapping content

From Dev

Relativelayout not wrapping its content

From Dev

Wrapping content height on a SnackBar

From Dev

Linear Layout not wrapping content

From Dev

Wrapping only the visible content

From Dev

Expand the clickable area of a html link to the size of the wrapping li element that contains other content

From Dev

Expand the clickable area of a html link to the size of the wrapping li element that contains other content

Related Related

  1. 1

    wrapping some content except the first element

  2. 2

    Prevent content from wrapping around floated element

  3. 3

    Removing every child element EXCEPT first child?

  4. 4

    Java - Removing an element from LinkedList except first

  5. 5

    How to shift except in the first element in array Javascript?

  6. 6

    Preferred way to iterate a List except the first element

  7. 7

    implement code for all elements except the first element

  8. 8

    Contenteditable bug when wrapping some text with link element

  9. 9

    Why isn't my TD element wrapping around text content?

  10. 10

    Why isn't my TD element wrapping around text content?

  11. 11

    jQuery get div content text and elements except some elements

  12. 12

    Xpath How to get text content from childs except some tags

  13. 13

    javascript check if an element content some part of an array

  14. 14

    Hide all except first child of an element using pure css

  15. 15

    How to remove cloned element div except first div using jquery

  16. 16

    Iterating over each element of an array, except the first one

  17. 17

    Check if all element except the first has a certain class

  18. 18

    How to remove cloned element div except first div using jquery

  19. 19

    c++ 98, vector, remove every element except the first one

  20. 20

    Capitalize first letter of various tags content element

  21. 21

    Need an array where with first element of new array=sum of all elements except the first element-Javascript

  22. 22

    iterating over elements in a vector, wrapping around from the last element to the first element in a circular fashion

  23. 23

    LinearLayout not wrapping content

  24. 24

    Relativelayout not wrapping its content

  25. 25

    Wrapping content height on a SnackBar

  26. 26

    Linear Layout not wrapping content

  27. 27

    Wrapping only the visible content

  28. 28

    Expand the clickable area of a html link to the size of the wrapping li element that contains other content

  29. 29

    Expand the clickable area of a html link to the size of the wrapping li element that contains other content

HotTag

Archive