On Nov 12, 2008, at 11:17 PM, Karl Swedberg wrote:

Hi Adam,

In that case, you'll probably need to use John Resig's nextUntil plugin.

The way I managed to do it is a little sneaky. Someone else should be able to come up with a better way. But in the meantime, you can take a look at a working example here

Just view source for the script.



Yikes! Somehow I managed to leave the URL for the test page out of the message. Sorry about that. I know the other way worked for you, but just in case you're interested, here is that link:

http://test.learningjquery.com/wrapall.html




On Nov 12, 2008, at 4:48 PM, Adam wrote:


Karl,
Thanks very much. My bad, but what I actually need is the div wrapped
around each of the sets of h1,p,p. So, the resulting code must be:

<div class='fade'>
<h1>...</h1>
<p>...</p>
<p>...</p>
</div>

<div class='fade'>
<h1>...</h1>
<p>...</p>
<p>...</p>
</div>

I have tried a number of different things, and this function works to
wrap the first set of 3 in the div:

$("#content h1:nth-child(1),#content p:nth-child(2),#content p:nth-
child(3)").wrapAll("<div class='fade'></div>");

so then I try to add another function to wrap the second set:

$("#content h1:nth-child(4),#content p:nth-child(5),#content p:nth-
child(6)").wrapAll("<div class='fade'></div>");

but I think the 'nth's get fouled up once the first function runs and
the results of adding the second function are very odd.

Any thoughts? Thanks (again) Karl!!

-Adam





On Nov 12, 2:14 pm, Karl Swedberg <[EMAIL PROTECTED]> wrote:
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 Swedbergwww.englishrules.comwww.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


Reply via email to