Ire Aderinokun 12/18/2018

A one-line solution to highlighting search matches

Read Original

The article details a developer's journey to implement search term highlighting on a blog. After exploring complex solutions, they discovered a concise one-line method using JavaScript's String.replace() with a regex and a function to wrap matches in <mark> HTML tags. It explains the replace() method's capabilities and notes a key limitation: the solution only works with plain text, not pre-existing HTML.

A one-line solution to highlighting search matches

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser