Hi Sean,
Actually, you can't use .next() in that situation.
The argument for .next() acts as a filter for what the very next
sibling can be. So, jQuery(this).next('#someId) will only select the
very next sibling, and only if it has an id of "someId"
cf. http://docs.jquery.com/Traversing/next
Also, I realize this is nitpicky, but in your example you should
probably write either next("#WhateverId") or next(".WhateverClass"),
but not next("#WhateverClass")
--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On Aug 31, 2007, at 9:17 AM, duma wrote:
Actually, since next() takes a selector as an argument, you can use
next().
Just do something like the following:
jQuery("div.faq h4").click(function() {
jQuery(this).next("#WhateverClass").addClass("top");
});
Sean
Karl Swedberg-2 wrote:
The .next() method will only select the very next sibling. If you
have other siblings in between the two h4s, you'll need to use a
different selector.
You could try this instead:
jQuery('div.faq h4').click(function() {
jQuery('~ h4:first', this).addClass('top');
});
That'll find the first sibling h4 that follows the clicked h4.
--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On Aug 30, 2007, at 8:03 PM, Josh Nathanson wrote:
Next() will only get siblings -- can you post the html?
-- Josh
----- Original Message ----- From: "ruperdupe" <[EMAIL PROTECTED]>
To: "jQuery (English)" <jquery-en@googlegroups.com>
Sent: Thursday, August 30, 2007 11:36 AM
Subject: [jQuery] next() problems
What I'm trying to do is when someone clicks on a h4 heading the
next
one has a class (top) added to it. In between each heading there
are
other elements. The h4s are inside a div called 'faq'.
So far I've tried:
jQuery('div.faq h4').click(function() {
jQuery(this).next().addClass('top');
});
And:
jQuery('div.faq h4').click(function() {
jQuery(this).next('h4').addClass('top');
});
Neither works and I can't figure out why? If anyone could help,
that
would be great!
(I'm using jQuery instead of $ because I'm using Prototype as well)
--
View this message in context: http://www.nabble.com/next%28%29-
problems-tf4357523s15494.html#a12426258
Sent from the JQuery mailing list archive at Nabble.com.