Wrap every occurrence of a word in a highlighted span
Given an HTML element and a specific word to look for, the task is to write a function that highlights the occurrences of that word within the text content of the element. The function should encapsulate the found word with a span element having a specified background color to visually emphasize the highlighted text. The native <mark> element is the semantic way to highlight text in HTML.
Consider the following HTML structure as an input example:
<div id="hello"> I have some text
<p>Which has some subtext <a href="#">that has a link</a></p>
<p>And a sibling</p>
Finally some random text
</div>
The objective is to highlight a word, for instance, “Finally”, within the div element with the id hello. The word “Finally” should be wrapped in a span element with a background color, for example, red, to visually differentiate it from the rest of the text.
This challenge requires manipulating the DOM to dynamically change the HTML content based on the text search criteria. The solution should ensure that only text content is affected without altering the inherent structure of the HTML or affecting nested elements such as <p> and <a>.