[jQuery] select range of code and wrap, multiple times

[jQuery] select range of code and wrap, multiple times


Hi folks, I hope you can help me out, I have a bit of html that looks
something like:
div
--h1
--h2
--p
--p
--h2
--ul
--h2
--p
And am trying to figure out a way to grab from that code each h2 and
its siblings, up-to-but-stopping-at the next h2, for example, I want
to grab from the simplified tree above: h2,p,p; then h2,ul; then 2,p
and wrap each group in a div so that the final result looks like
div
--h1
--div
----h2
----p
----p
--div
----h2
----ul
--div
----h2
----p
I hope what I need is clear and that you fine folks can help me out!