HTML
<div class="expand_content" style="overflow-y: hidden; height: 250px;">
A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph. A really long paragraph.
</div>
<div class="expand_more" style="cursor: pointer; text-align: right; color: #2D81FF; font-weight: bold;">read more...</div>
Javascript
document.querySelectorAll(".expand_more").forEach(function(element) {
element.addEventListener('click', function() {
var expand_content = this.previousElementSibling;
if (expand_content.style.height != "auto") {
sessionStorage.setItem("expand_height_orig", expand_content.style.height);
expand_content.style.height = "auto";
this.textContent = "collapse this...";
}
else {
var expand_height_orig = sessionStorage.getItem("expand_height_orig");
if (expand_height_orig) {
expand_content.style.height = expand_height_orig;
}
else {
expand_content.style.height = "25vh";
}
this.textContent = "read more...";
}
});
});