I have the following HTML structure:
An approach like this should work, though I'm guessing there are many different ways of doing this:
$('#subgroup h3').each(function() { $(this).nextUntil('h3').wrapAll(''); });