I've been working on a piece of code that identifies a specific string of characters (_aff.tractionsCode
) and swaps it out with another string (tractionsId
). The implementation looks something like this:
content = document.body.innerHTML.replace(_aff.tractionsCode, tractionsId);
document.body.innerHTML = content;
Let's illustrate this with an example:
Assume _aff.tractionsCode
is equal to {tractionsCode}
<div class="affiliate" rel="{tractionsCode}">{tractionsCode}</div>
This code should replace all instances of {tractionsCode}
The issue arises when the replacement occurs because it disrupts other JavaScript event handlers in the loaded HTML. These event handlers might not be accessible for modification.
Is there a way to search through the HTML, including its attributes like rel, make the replacements without altering the entire content?
Or, perhaps there's a more effective approach I could take?
Your assistance is greatly appreciated!