Hi,

Since you already have a reference to the slidebtn element at the
point you need it (it's "this" within the event handler), you can be a
bit more efficient just using Element#down[1] directly:

    fourthitem = this.down('li', 3);

[1] http://prototypejs.org/api/element/down

FWIW,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Jul 15, 7:51 am, Paul Kim <kimba...@gmail.com> wrote:
> Thanks Alex, this was exactly what I was looking for:
>
> for(i=0;i<=$$('#slidebtn li').length) {
>
> if(i==3) {
> alert('Got the 4th list element');
>
> }
>
> - Paul
>
> On Tue, Jul 14, 2009 at 11:08 PM, Alex McAuley <
>
>
>
> webmas...@thecarmarketplace.com> wrote:
> >  You can collect the LI's under the UL like this if you need to
>
> > $$('#slidebtn li')
>
> > then you have an array of elements you can use each on or you can access
> > directly ->
> > var i=0;
> >  $$('#slidebtn li').each(function(el) {
>
> >     if(i==2) {
> >     alert('Got the 3rd List element');
> > }
>
> > i++;
> > });
>
> > -----------------
>
> > Or
> > var second_list_item=$$('#slidebtn li')[1];
>
> > and so on
>
> > Or
>
> > for(i=0;i<=$$('#slidebtn li').length) {
>
> > if(i==3) {
> > alert('Got the 4th list element');
> > }
>
> > }
>
> > HTH
>
> > Alex
>
> > ----- Original Message -----
> > *From:* Paul Kim <kimba...@gmail.com>
> > *To:* prototype-scriptaculous@googlegroups.com
> > *Sent:* Wednesday, July 15, 2009 4:57 AM
> > *Subject:* [Proto-Scripty] Help! Is it possible to tell which element I
> > invoked without the use of id attribute
>
> > Hi, I have a simple unordered list:
>
> >     <ul id="slidebtn">
> >         <li><img src="img/1.gif" /></li>
> >         <li><img src="img/2.gif" /></li>
> >         <li><img src="img/3.gif" /></li>
> >         <li><img src="img/pause.gif" /></li>
> >     </ul>
>
> > I would like to know if it is possible to determine the nth <li> element
> > without the use of an id attribute:
>
> > document.observe("dom:loaded", function(){
> >     $('slidebtn').invoke('observe', 'click', function(e) {
> >         var element = Event.element(e);
> >         // this is where I need help
> >         // if element is first <li>, alert('0');
> >         // if element is second <li>, alert('1');
> >         // if element is third <li>, alert('2');
> >         // if element is fourth <li>, alert('3');
> >     });
> > };
>
> > Currently, I am doing this to return the src attribute value:
>
> > document.observe("dom:loaded", function(){
> >     $('slidebtn').invoke('observe', 'click', function(e) {
> >         var element = Event.element(e);
> >         // this will give me the src attribute value of the <img> element
> >         alert(element.src);
> >     });
> > };
>
> > The reason I want to return the nth index of the <li> element is so that I
> > can pass that as an argument to a function.
> > Any help in the right direction will be much appreciated.
>
> > - Paul K
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to