Implement Read More Read Less Functionality Using jQuery

Today, We want to share with you Implement Read More Read Less Functionality Using jQuery.In this post we will show you jQuery Read More/Less Toggle, hear for Implementing the ‘Read More’ Functionality Using jQuery we will give you demo and example for implement.In this post, we will learn about How to create the “More” link button to display rest of the text with an example.

Implement Read More Read Less Functionality Using jQuery

There are the Following The simple About Implement Read More Read Less Functionality Using jQuery Full Information With Example and source code.

As I will cover this Post with live Working example to develop jQuery/Javascript read more Plugins, so the some major files and Directory structures for this example is following below.

  • index.html

How to implement a “read more” link with jQuery

index.html

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.html.


  
    jQuery Read More/Less Toggle Example
	
	.loadaddContent span {
		display: none;
	}
	.livedataLink {
		display: block;
	}
	
	
	$(document).ready(function() {
    // Configure/customize these variables.
    var totalshow = 100;  // How many characters are shown by default
    var ellipsestext = "...";
    var moretext = "Show more >";
    var lesstext = "Show less";
    

    $('.more').each(function() {
        var dcont = $(this).html();
 
        if(dcont.length > totalshow) {
 
            var c = dcont.substr(0, totalshow);
            var h = dcont.substr(totalshow, dcont.length - totalshow);
 
            var html = c + '' + ellipsestext+ ' ' + h + '  ' + moretext + '';
 
            $(this).html(html);
        }
 
    });
 
    $(".livedataLink").click(function(){
        if($(this).hasClass("less")) {
            $(this).removeClass("less");
            $(this).html(moretext);
        } else {
            $(this).addClass("less");
            $(this).html(lesstext);
        }
        $(this).parent().prev().toggle();
        $(this).prev().toggle();
        return false;
    });
});
	
  
  
    
	 Pakainfo is the most popular Programming & Web Development blog. Our mission is to provide the best online resources on programming and web development. We deliver the useful and best tutorials for web professionals — developers, programmers, freelancers and site owners. Any visitors of this site are free to browse our tutorials, live demos and download scripts.
    
    

Pakainfo is the most popular Programming & Web Development blog. Our mission is to provide the best online resources on programming and web development. We deliver the useful and best tutorials for web professionals — developers, programmers, freelancers and site owners. Any visitors of this site are free to browse our tutorials, live demos and download scripts.

Javascript read more/less toggle Example

Implementing ‘Read More – Read Less’ using Javascript

index.html

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.html.

document.querySelector('.show-coontent-link').addEventListener('click', function() {
	// If your Data text is pakainfo display less, then display complete
	if(this.getAttribute('data-coontent') == 0) {
		this.setAttribute('data-coontent', 1);
		this.style.display = 'block';
		this.innerHTML = 'Read Less..';

		this.previousSibling.style.display = 'none';
		this.previousSibling.previousSibling.style.display = 'inline';
	}
	// If your Data text is pakainfo display complete, then display less
	else if(this.getAttribute('data-coontent') == 1) {
		this.setAttribute('data-coontent', 0);
		this.style.display = 'inline';
		this.innerHTML = 'Read More..';

		this.previousSibling.style.display = 'inline';
		this.previousSibling.previousSibling.style.display = 'none';
	}	
});
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Implementing ‘Read More – Read Less’ in jQuery Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment