I am building a Chrome extension which I would like to eventually have several features to add enhancements to an existing web application. The first of those features will be to add some hover-over (aka tooltip or mouse over) text to certain elements of certain pages within an existing website. Unfortunately the places on the page where I want to add the text to don't have any specific ID tags to reference, so I figured I would replace unique parts of the text on the page.
So here is an example of the code of the original webpage:
<html>
<table>
<tr>
<td>First Name</td>
<td>Last Name</td>
</tr>
<tr>
<td>John</td>
<td>Smith</td>
</tr>
</table>
</html>
And this is what I want it to look like after Javascript adds in the hover-over text (I am open to the way the hover-over text is applied, as long as it has hover-over text...I know applying span title tags works in Chrome):
<html>
<table>
<tr>
<td><span title="First Name of the student">First Name</span></td>
<td><span title="Last Name of the student">Last Name</span></td>
</tr>
<tr>
<td>John</td>
<td>Smith</td>
</tr>
</table>
</html>
This is the Javascript that I have so far. It works, but is there a way to make it more efficient, or is there a better way to do this?
document.body.innerHTML = document.body.innerHTML
.replace(/>First Name</g, '><span title="First Name of the student">First Name</span><')
.replace(/>Last Name</g, '><span title="Last Name of the student">Last Name</span><');
Thank you in advance for your help, an thank you for the opportunity to rewrite my question for clarity.