I have a unique problem with an HTML file that is out of my control when it comes to its content. My only option is to inject a CSS file and/or JavaScript (potentially using libraries like jQuery) into the mix.
Within this HTML, there are elements that require highlighting and tooltips added to them. These elements may not be conveniently grouped in specific containers for easy styling. They could be <span>
, <a>
, <img>
, <div>
, or any other type of element (inline or block).
While my preference is to use pure CSS to solve this challenge, I am open to utilizing JavaScript to manipulate the Document Object Model if necessary. However, the end result must maintain the same layout as the original HTML, with just the highlights floating over the specified elements.
For instance, if the original HTML looks like this:
<body>
<p>This is a sample line of text with <a href="#">a link</a> in the middle that should be highlighted</p>
<p>This is a sample line of text with <a href="#" data-highlight="true">a link</a> in the middle that should be highlighted</p>
</body>
The desired outcome would resemble something like this: