
How to create read more in jquery
Created at 16-Aug-2021 ,
By samar
How to create read more in jquery
We will use programming in this lesson to attempt to solve the "How to create read more in jquery".
Read more is the most common functionality which is used to see all specified content in the block. By default, we hide the content and assign the read more button to it and on clicking it we show the whole content using jquery.-
Read more functionality using jquery in html
<!-- Paste the below code in the Head tag of your HTML page --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <style> .show-read-more .more-text{ display: none; } </style> <!-- Paste the below code in the body tag of your HTML page --> <p class="show-read-more"> It is a long-established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many websites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humor and the like). </p> <script> var maxLength = 300; $(".show-read-more").each(function(){ var myStr = $(this).text(); if($.trim(myStr).length > maxLength){ var newStr = myStr.substring(0, maxLength); var removedStr = myStr.substring(maxLength, myStr.length); $(this).empty().html(newStr); $(this).append(' <a href="javascript:void(0);" class="read-more">read more...</a>'); $(this).append('<span class="more-text">' + removedStr + '</span>'); } }); $(".read-more").click(function(){ $(this).siblings(".more-text").contents().unwrap(); $(this).remove(); }); </script>
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Jquery
- Preview image in base64 format using jQuery on change input file
- Get the href link on click anchor in javascript
- How to use and purpose of localstorage in javascript
- How to check ajax request is completed in jQuery
- How to check object is empty or not in jQuery
- Ajax for multiple form
- Add and remove input fields on click button using jQuery
- How to find closest upper element and append html to below it in jquery
- Jquery.validate.min.js:4 Uncaught TypeError: Cannot read properties of undefined (reading 'mode')
- Preview image in BLOB URL format on choose file in jQuery
- Jquery-3.6.0.min.js CDN link
- How to validate input type file size in jQuery for multiple records
- Show loading icon on click submit button in jQuery
- JQuery append html to below the target element
- How to pass javascript variable to laravel route on ajax call
- How to preview image before uploading in jQuery
- How to reset form input element on click
- How to get closest form input value in jQuery
- How to remove Choose File button in jquery
- Ajax done fail ajaxcomplete in not a function
- Show and hide target element on click button using javascript/jquery
- Append method to add text to body not working
- Execute function after Ajax call is complete
- Uncaught TypeError: $.ajax is not a function
- Enable click event on appended element using jQuery