
jQuery find text and show as bold in html page
jQuery find text and show as bold in html page
We’ll attempt to use programming in this lesson to solve the "jQuery find text and show as bold in html page" puzzle.
You can find text and show as bold in html page using jQuery. You have to pass the words to method which you want to make bold or highlight in html page.-
JQuery find text and highlight in html page
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Optio temporibus, voluptate libero consequatur aut ullam accusamus officia minus, minima ratione quasi vero qui tenetur quam enim repellat, cum ipsa saepe.</p> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script> <script> $.fn.wrapInTag = function(opts) { var tag = opts.tag || 'strong', words = opts.words || [], regex = RegExp(words.join('|'), 'gi'), replacement = '<'+ tag +'>$&</'+ tag +'>'; return this.html(function() { return $(this).text().replace(regex, replacement); }); }; $('p').wrapInTag({ tag: 'strong', words: ['consectetur'] }); </script> <!-- Output: --> <!-- <p>Lorem, ipsum dolor sit amet <strong>consectetur</strong> adipisicing elit. Optio temporibus, voluptate libero consequatur aut ullam accusamus officia minus, minima ratione quasi vero qui tenetur quam enim repellat, cum ipsa saepe</p> -->
This code snippet will help you to find out the specified text which you want to highlight or make it bold in html page. You can pass tag name to tag and words with comma separated to words in wrapInTag() method.
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 reset form input element on click
- Mixed Content: The page at 'https://w3codegenerator.com/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint
- Show loading icon on click submit button in jQuery
- How to check ajax request is completed in jQuery
- Uncaught TypeError: $.ajax is not a function
- How to preview image before uploading in jQuery
- JQuery append html to below the target element
- Jquery.validate.min.js:4 Uncaught TypeError: Cannot read properties of undefined (reading 'mode')
- How to use and purpose of localstorage in javascript
- Preview image in BLOB URL format on choose file in jQuery
- Execute function after Ajax call is complete
- Show and hide target element on click button using javascript/jquery
- Preview image in base64 format using jQuery on change input file
- Jquery-3.6.0.min.js CDN link
- How to validate input type file size in jQuery for multiple records
- Ajax for multiple form
- How to pass javascript variable to laravel route on ajax call
- Ajax done fail ajaxcomplete in not a function
- Uncaught TypeError: $.ajaxSetup is not a function
- How to get closest form input value in jQuery
- Append method to add text to body not working
- Add and remove input fields on click button using jQuery
- How to create read more in jquery
- Enable click event on appended element using jQuery
- How to check object is empty or not in jQuery