I'm working on a small javascript that would change the look of certain page and to do so I have to change certain parts of the HTML (that means that it can't be changed through CSS). The only solution I managed to find so far is the function replace() in javascript. However it seems like a pretty unfortunate solution to change the innerHTML directly even though it's the fastest way from what I know.
Here is the original html:
<div data-sigil="touchable" class="_52x6 touchable">
<a href="/messages/?ref=bookmarks&app_id=217974574879787" class="_5lut _5luu">
<div class="_52x3">
<i class="_5i9c img" style="background-image: url(https://static.xx.fbcdn.net/rsrc.php/v2/yH/r/d3XxBNxqXrK.png);"></i>
</div>
<div class="_52x7">Messages</div>
<div class="_55fj hiddenElem">
<span>0</span>
<span class="_55fk">new</span>
</div>
</a>
</div>
And I want to change the link
in background-image: url(link);
to load different image instead of the original one. And then I want to change Messages
in <div class="_52x7">Messages</div>
to Mail
.
What is the problem? These elements don't have their unique IDs so it's not possible to use getElementById()
to find them and if I replace these strings within entire html, it will break all links and scripts on the page. (because of how innerHTML works)
Is there any possible way to replace mentioned strings? (I can't use jQuery and all the classes are quite common in the html so I can't use getElementsByClassName() either, unless I'd cycle through all of them, but that seems like a pretty unfortunate solution to me)