Wrapping an unknown number of elements
Hi all,
Excuse the possibly n00b question as i'm quite new to jQuery.
This is probably easiest shown by example.
I am developing a greasemonkey script with jQuery to restructure and tidy up some HTML source over which I have no control.
I want to be able to wrap each of an arbitrary number of blocks into a div. The trouble i'm having is that some blocks have two elements and some have three.
Here's an example. I want to transform:
-
<h2>Items</h2>
<a href="x">title</a>
<p>description</p>
<b>optional note</b>
<a href="y">title</a>
<p>description</p>
<a href="z">title</a>
<p>description</p>
<b>optional note</b>
to
-
<h2>Items</h2>
<div class="item">
<a href="x">title</a>
<p>description</p>
<b>optional note</b>
</div>
<div class="item">
<a href="y">title</a>
<p>description</p>
</div>
<div class="item">
<a href="z">title</a>
<p>description</p>
<b>optional note</b>
</div>
I'm having trouble using the selectors to group the correct elements together in order to then wrap them.
Can anyone suggest a way to handle this problem?