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 <
[email protected]> 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 <[email protected]>
> *To:* [email protected]
> *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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---