javascript - use jQuery to expand/collapse text -


I want to cut text based on fixed altitude. When the text is cut, the "more" link is used to expand the text when the text is expanded, a "short" link is used to compress the text. The form has been written in:

  $ (document) .ready (function () {// line height in 'px' max maxheight = 218; var showText = "more"; var hideText = " Less "; $ ('textContainer_Truncate') each (function () {var text = $ (this); if (text.height (>> gt; max) {text.css ({'overflow': 'hidden var, Height ': maxheight +' px '}); var link = $ (' & lt; a href = "#" & gt; '+ showText +' & lt; / a & gt; '); var li NkDiv = $ ('
& lt; / div & gt;'); linkDiv.append (link); $ (this) .after (linkDiv); link.click (event) {event .preventDefault (); if (text.css) == 'auto') {$ (this) .html (shoutex); text css ('height, maximum rights' 'px');} and {$ (This) .html (hidden text); text css ('height', 'auto');}}}}}});});

The html code is:

    

My problem is that the "more" link works but does not "less" is this, when more clicks are done, the text is expanded, but with fewer clicks It will not go back. What's wrong here? Thank you

This is just a minor error, this:

  If (Text.css ('height') == 'auto') {  

should be:

  if (text.height ()> maximum write ) {  



Comments