Adding multiple ReadMore ReadLess Links
Adding multiple ReadMore and ReadLess Links
This post explains to you how to add multiple read more and readless links to a multiple blog posts in a single page. So here is the example.
It
is a common practice in modern website designing. Including 'readmore'
and readless button when text is too long to show it in webpage, for
this we can use viewmore or 'read more' button. So that user will click on
it if he is interested to read complete content. For this you can use
either button or links as per your choice.
In this, we are using some CSS and JavaScript to implement the 'showmore' and showless links to display content.
Example:
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>e-Trainings Demo -Adding several ReadMore ReadLess Links to each blog post </title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> <style> .showmore { font-size: 1.1em; margin-top: 1.5em; } .showmore .more, .showmore.show .dots { display: none } .showmore.show .more { display: inline } .showmore a { cursor: pointer; display: block; margin-top: 0.5em; margin-bottom: 1em; font-weight: bold; } </style> </head> <body> <div class="container-fluid"> <div class="row"> <div class="col-sm-12" id="d1"> <h4><small>RECENT POSTS </small></h4> <hr> <h2>Read More Read Less Link</h2> <h5><span class="glyphicon glyphicon-time"></span> Post by Jane Dane, Jun 27, 2021.</h5> <h5><span class="label label-danger">Technoloty</span> <span class="label label-primary">Ipsum</span></h5><br> <p class="showmore">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Excepteur sint occaecat cupidatat And here is a second paragraph. <span class="dots">...</span><span class="more"> This is the hidden text. This is the hidden text. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Excepteur sint occaecat cupidatat </span> <a>Show More</a> <br> </div> </div><hr> <div class="row"> <div class="col-sm-12" id="d2"> <h2>Read More Read Less Link</h2> <h5><span class="glyphicon glyphicon-time"></span>Post by Jane Dane, Jun 27, 2021.</h5> <h5><span class="label label-danger">Technoloty</span> <span class="label label-primary">Ipsum</span></h5><br> <p class="showmore">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Excepteur sint occaecat cupidatat And here is a second paragraph. <span class="dots">...</span><span class="more"> This is the hidden text. This is the hidden text. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Excepteur sint occaecat cupidatat </span> <a>Show More</a> </p> <br> </div> </div> <hr> <script type="text/javascript"> document.querySelectorAll(".showmore").forEach(function (p) { p.querySelector("a").addEventListener("click", function () { p.classList.toggle("show"); this.textContent = p.classList.contains("show") ? "Show Less" : "Show More"; }); }); </script> <div class="as-console-wrapper"><div class="as-console"> </div></div> </body> </html>
Demo:
Comments
Post a Comment