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)" <[email protected]>
>> 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.