Jquery Basic Beginner Question: How do i make my function reusable?

Posted by obikodi on Stack Overflow See other posts from Stack Overflow or by obikodi
Published on 2010-04-20T08:37:53Z Indexed on 2010/04/20 8:43 UTC
Read the original article Hit count: 247

Filed under:
|
|
|

I have spent the last few hours attempting to do this on my own, and using Google to find a solution but to no avail.

So if you can help out i would super appreciate it!

Basically I have a page which has 3 separate biographies in 'preview mode', which shows only the first paragraph of each bio.

When you click on 'read more' for one bio it opens up the 'full mode'.

What is happening at the moment, is if i click on one 'read more' link, it opens up the full mode on all 3 bio's.

How do i edit the following code so;

  • It only opens the full mode bio of the link i click on
  • Make it reusable so i don't have to duplicate the code 3 times for each bio

$("a#btnReadMore").click(function(){ $('.readMoreSlider').slideToggle("fast"); $(this).toggleClass("readMoreSliderActive"); return false; });

Thanks for your help!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about reuse