Another possible solution, might be a bit faster: $('#clickedItems a').each(function(i){ $(this).click(function(){ $('#targetedArea li').eq(i).html('woo'); }); });
On Nov 3, 9:11 pm, sperks <[EMAIL PROTECTED]> wrote: > Thanks Klaus, > > I got another answer elsewhere (apologies for doubling up the > request). > > Here's the answer I got from the other forum which is similar to your, > but I found it more in tune with my scripting style: > > $('#clickedItems a').click(function() { > // figure out what position this element is in > var n = $('#clickedItems a').index($(this) ); > // update the targetedArea > $('#targetedArea li:eq('+n+')').html('updated!'); > return false; > > }); > > On Nov 3, 5:30 pm, Klaus Hartl <[EMAIL PROTECTED]> wrote: > > > var $a = $('#clickedItems a').click(function() { > > $('#targetedArea li').eq($a.index(this)).addClass('active'); > > return false; > > > }); > > > --Klaus > > > On 3 Nov., 23:24, sperks <[EMAIL PROTECTED]> wrote: > > > > I'm wanting to target the nth <li> in a list after clicking the nth > > > link. > > > > <ul id="targetedArea"> > > > <li></li> > > > <li></li> > > > <li></li> > > > <li></li> > > > </ul> > > > <div id="clickedItems"> > > > <a></a> > > > <a></a> > > > <a></a> > > > <a></a> > > > </div> > > > > I can target them all individually, but I know there must be a faster > > > way by maybe passing the what <a> element I clicked on. > > > > $("#clickedItem a:eq(2)").click(function() { > > > $("#targetedArea:eq(2)").addClass('active'); > > > return false; > > > }); > > > > Cheers, > > > Steve