:after is used to insert generated content after an element, not to select the next element. In your code, the :after(...) is doing nothing, it reads as $('ul.tab-menu a').eq(index + 1) - what's working is the index.
You don't need to save the index as it's in the scope of the function: $('#tabs img.albumImage').each(function(index) { var $tabs = $('ul.tab-menu a'); $(this).click(function() { // in albums, clicking on an image brings the user to the next image $( $tabs[index + 1] ).click(); }); }); The selector you were after is $('li:has(.tab-menu-item-selected) + li a.tab-menu-item'), but doing the whole parent().next().children('a.tab- menu-item') stuff is faster, despite being verbose. cheers, - ricardo On Mar 4, 1:01 pm, Joseph Le Brech <jlebr...@hotmail.com> wrote: > http://docs.jquery.com/DOM/Traversing/Selectors#Not_supported > > i seen the + operator seems to do something similar, it means an element > preceding. > > Date: Wed, 4 Mar 2009 16:54:46 +0100 > Subject: [jQuery] Re: next() question > From: aplennev...@gmail.com > To: jquery-en@googlegroups.com > > thanks i got it to work, sort of. > > $('#tabs img.albumImage').each(function(index) > { > var $img = $(this).data('tabindex', index); > $img.click(function() > { > // in albums, clicking on an image brings > the user to the next image > var index = $(this).data('tabindex'); > > $('ul.tab-menu > a:after("a.tab-menu-item-selected")').eq(index + 1).trigger('click'); > }); > }); > > :after is not documented on the jquery selector > page:http://docs.jquery.com/Selectors > > should it be added? > > On Wed, Mar 4, 2009 at 4:21 PM, Joseph Le Brech <jlebr...@hotmail.com> wrote: > > you should be able to use the :after pseudo element > > http://www.w3.org/TR/CSS2/selector.html#before-and-after > > > Date: Wed, 4 Mar 2009 16:10:03 +0100 > > Subject: [jQuery] next() question > > From: aplennev...@gmail.com > > To: jquery-en@googlegroups.com > > - Show quoted text - > > > > > > > Hello, > > > say i have this markup: > > > <ul class="tab-nav-menu tab-menu"> > > <li><a class="tab-menu-item tab-menu-item-selected" > > href="#fragment0">0</a></li> > > <li><a class="tab-menu-item" href="#fragment1">1</a></li> > > <li><a class="tab-menu-item" href="#fragment2">2</a></li> > > <li><a class="tab-menu-item" href="#fragment3">3</a></li> > > <li><a class="tab-menu-item" href="#fragment4">4</a></li> > > < li><a class="tab-menu-item" href="#fragment5">5</a></li> > > <li><a class="tab-menu-item" href="#fragment6">6</a></li> > > <li id="imageLegend">Arca 180</li> > > > </ul> > > > I need to find the anchor link that immediately follows > > a.tab-menu-item-selected. i tried using next but i never get it right > > > $('a.tab-menu-item-selected').next('a.tab-menu-item').length returns always > > 0 > > > any idea how to find this selector would be greatly appreciated. > > > Thanks > > > Alexandre > > Windows Live Messenger just got better. Find out more! > > _________________________________________________________________ > 25GB of FREE Online Storage – Find out > morehttp://clk.atdmt.com/UKM/go/134665320/direct/01/