I have a text and I want when a user search for a term, the term becomes highlighted by wrapping the term with mark tag.
javascript to wrap the match term:
innerHTML
will destroy eventsinnerHTML
will trigger regeneration of the DOMTo make thins easy you should use an existing plugin. There are many jQuery plugins out there, but as you haven't added the jquery
tag I assume that you're searching a plain JS solution. Then the only plugin is mark.js.
Example of your use case