Skip to content

Instantly share code, notes, and snippets.

@softiconic
Last active December 2, 2023 18:49
Show Gist options
  • Save softiconic/d94576018aee62ffabe078290c37410a to your computer and use it in GitHub Desktop.
Save softiconic/d94576018aee62ffabe078290c37410a to your computer and use it in GitHub Desktop.
Implement a "Read More" functionality for content using JavaScript.
<div class="sccontent">
<p>default text here</p>
<p class="moretext">
more text here
</p>
</div>
<a class="readmore" href="#">Read more</a>
<style>
.moretext {
display: none;
}
</style>
<script>
jQuery('.readmore').click(function () {
jQuery('.moretext').slideToggle();
if (jQuery('.readmore').text() == "Read more") {
jQuery(this).text("Read less")
} else {
jQuery(this).text("Read more")
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment