istos
istos

Reputation: 2662

issue with "this" keyword in plugin and jQuery animate()

I am trying my luck at authoring a plugin with jQuery but I am having a few issues. So I want to make this plugin where I take some divs and add a read more or read less link after these divs.

When the read more link is clicked, I want to animate each div's height to the original height (I say original because the div's height is shortened before the link is clicked), and set the read more text link to read less - and then the other way around. Similar to the slideToggle effect.

My issue seems to be the "this" keyword, animate() function, or perhaps it is a logic issue... not sure. Here is a link to a live example: http://jsfiddle.net/f978v/

Any help would be much appreciated!

Upvotes: 0

Views: 173

Answers (2)

istos
istos

Reputation: 2662

In an effort to let others know about my implementation of this plugin, here is the complete code: truncate plugin code

Upvotes: 0

ShankarSangoli
ShankarSangoli

Reputation: 69915

The issue is because of the if condition inside trunc method where you check for linkTxt and decide to increase or reduce the height. Since you are using a local variable linkTxt to pass the text to trunc method it is always read more.... I have fixed in the below link, take a look

Working Demo

Upvotes: 2

Related Questions