Oh, I just tried it and actually you're right!  Bummer.  It worked in
the code I was using, anyway ;-)

That behavior actually doesn't make much sense to me; it doesn't seem
like, in practive, you'd ever have immediate siblings that could be
some class (or whatever) that you don't expect.  Selecting the next
matching element makes more sense.

Sean

On Aug 31, 11:08 am, Karl Swedberg <[EMAIL PROTECTED]> wrote:
> 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 Swedbergwww.englishrules.comwww.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.- Hide quoted text -
>
> - Show quoted text -

Reply via email to