Hi Adam,
Take a look at the .wrapAll() method. that should get you closer.
You'll need to select all of the elements first, though. $('h1 + p +
p') only selects that final p. If you want to wrap the div around all
h1 and p elements, you could try $('h1,p').wrapAll('<div
class="fade"></div>');
--Karl
____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On Nov 12, 2008, at 2:11 PM, Adam wrote:
I am trying to figure out how to select 3 elements that occur together
and wrap all 3 together (not individually) in a DIV tag. This is what
I have:
<h1>...</h1>
<p>...</p>
<p>...</p>
<h1>...</h1>
<p>...</p>
<p>...</p>
and I want to turn that into:
<div class='fade'>
<h1>...</h1>
<p>...</p>
<p>...</p>
<h1>...</h1>
<p>...</p>
<p>...</p>
</div>
I have tried using the ("h1 + p + p") with .wrap, but this seems to
detect the trio, but only wrap the last p. How can I make it wrap the
trio together?
Thanks!
-Adam