Languages
[Edit]
EN

JavaScript - mark matching text in HTML document with specific marker

5 points
Created by:
Root-ssh
178170

In this article, we want to show how to write in JavaScript simple logic that finds in indicated element (it can be the whole document) matching text and highlights it using indicated styles (indicated marker).

That logic lets us to group highlighted texts and use different markers.

Marked text in the indicated HTML element using different marker groups - JavaScript
Marked text in the indicated HTML element using different marker groups - JavaScript

Note: to see a simpler version check this article.

Below code usage example:

The solution doesn't change document formatting - just wraps the matching test with an additional neutral element that marks matching text.

Keywords can be described as a regular expression that makes below logic very elastic.

Practical example:

 

See also

Edit
  1. JavaScript - mark matching text in HTML document 

Alternative titles

  1. JavaScript - mark matching text in element with specific marker
  2. JavaScript - highlight matching text in HTML document with specific marker
  3. JavaScript - highlight matching text in element with specific marker
  4. JavaScript - find and mark text in the web page with specific marker
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join