jQuery: Wrap elements with nextUntil()

Martin
<h2 id="match" class="contentHeadline">Match only in here</h2>

<p>I don't if or how many dl+table live here.</p>

<dl><dt>Text</dt></dl>
<table class="groupTable"><td>1</td><td>Abc</td></table>

<dl><dt>Text</dt></dl>
<table class="groupTable"><td>2</td><td>Def</td></table>

<dl><dt>Text</dt></dl>
<table class="groupTable"><td>3</td><td>Ghi</td></table>

<p class="foo">Maybe some text lives here. I should not float.</p>

I want to wrap each pair of dl + table in a div.box (floating), but only directly under h2#match until other stuff following (.foo or headlines).

$("dl").each(function(){
    $(this).next('.groupTable').andSelf()
        .wrapAll('<div class="box"></div>');
});

/* Clear */
$('<div class="clear"></div>').after('.box:last');

nextUntil() wraps dl and the table individually.

Atm the test group is wrongly wrapped.

Test: http://jsfiddle.net/GQwB5/

Desired result: http://jsfiddle.net/kppQ9/

pete

$('#match').nextUntil('.contentHeadline') works well.

Applied:

$('#match').nextUntil('.contentHeadline').filter('dl').each(function(){
    $(this).next('.groupTable').andSelf().wrapAll('<div class="box" />');
});
$('#match').nextUntil('.contentHeadline').filter('.box:last').after('<div class="clear" />');

Fiddle: http://jsfiddle.net/GQwB5/1/

I suspect that .nextUntil(".foo, .contentHeadline") won't work because it expects a single matching element, and that would return at least two.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Wrap elements into div with jQuery

From Dev

jQuery, nextUntil(), if element is not a paragraph

From Dev

Using jQuery to wrap elements in a hyperlink

From Dev

Jquery wrap elements inside div

From Dev

Wrap groups of elements using jQuery

From Dev

Wrap function Jquery for multiple elements

From Dev

Using jQuery to wrap elements in a hyperlink

From Dev

Wrap groups of elements using jQuery

From Dev

Using jQuery .nextUntil() on split lists

From Dev

How to wrap groups of two elements in jQuery?

From Dev

How to wrap elements in a group of items with jQuery?

From Dev

jQuery wrap multiple elements independent of level

From Dev

Wrap div around 2 sequential elements in jQuery

From Dev

Wrap elements inside another using classes in jQuery

From Dev

Wrap around groups of elements using jQuery

From Dev

Wrap a div around every 2 elements in jQuery

From Dev

Wrap multiple selected elements with a div with jquery

From Dev

Wrap group of elements in multiple HTML elements using JQuery

From Dev

Hide on click Angular JS - jQuery nextUntil() functionality

From Dev

Jquery Next/NextAll/NextUntil with count limit

From Dev

Wrap tags around items inside existing <li> elements using jQuery

From Dev

How Do I wrap only selected elements in jQuery

From Dev

How to wrap all elements inside a div after a certain element? (JQuery)

From Dev

JQuery collect group of elements, unwrap each and then wrap all in new element

From Dev

jQuery wrap list elements containing the same text part

From Dev

Using jquery / javascript to wrap a series of HTML elements in Wordpress

From Dev

jQuery wrap() in on()

From Dev

jQuery $(this).nextUntil('h3').toggle(); - hidden ul inside an ul

From Dev

How to wrap all HTML elements in a DIV depending on total height of those HTML elements using jQuery?

Related Related

  1. 1

    Wrap elements into div with jQuery

  2. 2

    jQuery, nextUntil(), if element is not a paragraph

  3. 3

    Using jQuery to wrap elements in a hyperlink

  4. 4

    Jquery wrap elements inside div

  5. 5

    Wrap groups of elements using jQuery

  6. 6

    Wrap function Jquery for multiple elements

  7. 7

    Using jQuery to wrap elements in a hyperlink

  8. 8

    Wrap groups of elements using jQuery

  9. 9

    Using jQuery .nextUntil() on split lists

  10. 10

    How to wrap groups of two elements in jQuery?

  11. 11

    How to wrap elements in a group of items with jQuery?

  12. 12

    jQuery wrap multiple elements independent of level

  13. 13

    Wrap div around 2 sequential elements in jQuery

  14. 14

    Wrap elements inside another using classes in jQuery

  15. 15

    Wrap around groups of elements using jQuery

  16. 16

    Wrap a div around every 2 elements in jQuery

  17. 17

    Wrap multiple selected elements with a div with jquery

  18. 18

    Wrap group of elements in multiple HTML elements using JQuery

  19. 19

    Hide on click Angular JS - jQuery nextUntil() functionality

  20. 20

    Jquery Next/NextAll/NextUntil with count limit

  21. 21

    Wrap tags around items inside existing <li> elements using jQuery

  22. 22

    How Do I wrap only selected elements in jQuery

  23. 23

    How to wrap all elements inside a div after a certain element? (JQuery)

  24. 24

    JQuery collect group of elements, unwrap each and then wrap all in new element

  25. 25

    jQuery wrap list elements containing the same text part

  26. 26

    Using jquery / javascript to wrap a series of HTML elements in Wordpress

  27. 27

    jQuery wrap() in on()

  28. 28

    jQuery $(this).nextUntil('h3').toggle(); - hidden ul inside an ul

  29. 29

    How to wrap all HTML elements in a DIV depending on total height of those HTML elements using jQuery?

HotTag

Archive