[jQuery] Re: Setting identical events to multiple elements using a for loop

2009-07-26 Thread FrenchiINLA
in your case you can use: $('span[id^sp_span]') to get all span with id starting with sp_span then you can get the id when is clicked $('span[id^sp_span]').click(function(){ var spanID = $(this).attr('id').split('_')[1] ;will give you span1, span2 etc $('#'+spanID).slideToggle(slideSpeed); });

[jQuery] Re: Setting identical events to multiple elements using a for loop

2009-07-26 Thread FrenchiINLA
sorry i got a typo error, the corrent code is: $('span[id^=sp_span]'). On Jul 26, 8:39 am, FrenchiINLA mamali.sohe...@gmail.com wrote: in your case you can use: $('span[id^sp_span]') to get all span with id starting with sp_span then you can get the id when is clicked

[jQuery] Re: Setting identical events to multiple elements using a for loop

2009-07-26 Thread Blake
Okay, it seems to work well. Here is the jQuery that I have now: -- $('span[id^=sp_span]').click(function(){ var spanID = $(this).attr('id').split('_')[1]; $('#'+spanID).slideToggle(slideSpeed); $('span.contentSpan:not(#'+spanID+')').slideUp(slideSpeed); }); -- First of all -

[jQuery] Re: Setting identical events to multiple elements using a for loop

2009-07-26 Thread Blake
Oh, and...can I use a for loop to give me the result I want? On Jul 26, 10:33 am, Blake stickynote...@gmail.com wrote: Okay, it seems to work well. Here is the jQuery that I have now: -- $('span[id^=sp_span]').click(function(){ var spanID = $(this).attr('id').split('_')[1];

[jQuery] Re: Setting identical events to multiple elements using a for loop

2009-07-26 Thread Blake
I'm sorry for posting yet again, but it appears I may be able to use a for loop. Here is what I have (jQuery): -- for (i=0;isections.length-1;i++) { $(span#sp_+sections[i]).click(function() { $(span#+sections[i]).slideToggle(slideSpeed);