Help me reduce code repetition in a simple jQuery function

Posted by user339876 on Stack Overflow See other posts from Stack Overflow or by user339876
Published on 2010-05-13T01:30:06Z Indexed on 2010/05/13 1:34 UTC
Read the original article Hit count: 235

Filed under:
|

I have built a carousel using the jQuery cycle plugin. I have 4 links that jump to relevent slides. Right now I have a chunk of code for each link. I am trying to create a single multi-purpose function.

   $('#features-slide0').click(function() {  
       $('#features-slides').cycle(0);  
       return false;  
   });

   $('#features-slide1').click(function() {  
       $('#features-slides').cycle(1);  
       return false;  
   });

   $('#features-slide2').click(function() {  
       $('#features-slides').cycle(2);  
       return false;  
   });

   $('#features-slide3').click(function() {  
       $('#features-slides').cycle(3);  
       return false;  
   });

I have a rel value on each link that carries the number of the slide. How can I use that to create a single block of code that takes care of the link jump?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript