I am trying to limit an element's characters to 90 words normally. But when the show more button is clicked it should remove the limit.
I tried using a class to do this and attaching the limit to the class and then removing the class when the show more button is clicked.
My attempt at this:
<header>
<h1>Heading Goes Here</h1>
<p class="jumbo-p non-exp">
The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.
</p>
<a href="#" class="more1">more</a>
</header>
The CSS:
.jumbo-p{display: inline-block; height: 20px; overflow: hidden;}
.more1 {position: relative; left: 2px; top: -21px;}
.jumbo-p.expanded+.more1 {display: none}
.jumbo-p.expanded {height: auto;}
The jQuery to make it all work:
$(".non-exp").text(function(index, currentText) {
return currentText.substr(0, 90) + '...';
});
$(document).on('click', '.more1', function(event) {
event.preventDefault();
$('.jumbo-p').toggleClass('expanded');
$('.jumbo-p').removeClass('non-exp');
});
This puts the limit on the div but that limit is not removed when the class is removed. Please help.