How to create show more and show less functionality for hiding text using jQuery

We can add Read More/Read Less button next to a too long HTML element by using jQuery.The amount of content displayed can be changed by clicking on the buttons. Instead of showing a complete paragraph on a webpage, only some part of the text is shown initially and a button is added which shows more of the text.

  hide: function () {
            var txt = $(".readmore-text").is(':visible') ? 'Read More' : 'Read Less';
            $(".read-more-btn").text(txt);
            $(".readmore-text").slideToggle();
        },

Leave a comment

Your email address will not be published. Required fields are marked *