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
- How to find closest upper element and append html to below it in jquery
- Ajax done fail ajaxcomplete in not a function
- How to reset form input element on click
- (index):128 Uncaught TypeError: MobileNumberVal.test is not a function
- How to remove Choose File button in jquery
- How to pass javascript variable to laravel route on ajax call
- Uncaught TypeError: $.ajaxSetup is not a function
- Show loading icon on click submit button in jQuery
- How to use and purpose of localstorage in javascript
- Ajax for multiple form
- How to get closest form input value in jQuery
- Uncaught TypeError: $.ajax is not a function
- How to check ajax request is completed in jQuery
- How to preview image before uploading in jQuery
- Jquery.validate.min.js:4 Uncaught TypeError: Cannot read properties of undefined (reading 'mode')
- Validate form using jQuery
- Get the href link on click anchor in javascript
- Jquery-3.6.0.min.js CDN link
- How to check object is empty or not in jQuery
- Show and hide target element on click button using javascript/jquery
- Execute function after Ajax call is complete
- Preview image in BLOB URL format on choose file in jQuery
- Add and remove input fields on click button using jQuery
- Enable click event on appended element using jQuery
- Mixed Content: The page at 'https://w3codegenerator.com/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint