javascriptjqueryhtmlwrapall

wrapAll 3 class elements


I'm stuck with trying to capsulate 3 divs inside one wrapping div. So far I have managed to get 2 divs wrapped up, but I can't figure out the last one.

You can see my JSFiddle here: http://jsfiddle.net/cz9eY/

$('.input_jq_checkbox').each(function(){
$(this).next('label').andSelf().wrapAll('<div class="test"/>');
});

Solution

  • If you use $(this).nextAll(':lt(2)').andSelf() you'll get the label and the next two elements.