I'm working on a personal project and I'm having a small issue:
This is my code code and currently works: http://jsfiddle.net/gvM3b/:
$(".show-more").click(function () {
$(this).text("(Show Less)");
$(".text").toggleClass("show-more-height");
});
The issue is that the "(Show More)" text changes to "(Show Less)" but not switches back when needed.
^That's one thing, an additional thing would be if you know how to add the [...] when it says show more but on the text. Been trying to figure it out but had to ask for a little of help, I'm new to jquery.
Thanks!
Like this:
updated fiddle
Update your jQuery:
See http://jsfiddle.net/gvM3b/1/
I'd like to recommend the Jquery more less library which takes care of the 'Show More' 'Show Less' problem.
An alternative: cmtextconstrain
Use the ternary operator, for example:
Or using
.text()
with a function:DEMO.
Here's one more solution:
The fiddle: http://jsfiddle.net/gvM3b/6/