JSFiddle - React, Tailwind, and code Playground
by Qwerty_Wasd
HTML
<a href="http://hello.com/">hello link</a>
<br/>
<p data-value="http://hello.com/">hello link</p>
<br/>
<span title="http://hello.com/">hello link</span>
JavaScript
const getANode = (wrapper = document.body) => {
let walker = document.createTreeWalker( wrapper, NodeFilter.SHOW_ALL, { acceptNode: node => node instanceof HTMLElement && node.getAttributeNames().length ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP }, false );
while (walker.nextNode()) {
walker.currentNode.getAttributeNames().forEach(e => {
walker.currentNode.setAttribute(e, walker.currentNode.getAttribute(e).replace(/hello/, `world`));
});
walker.currentNode.textContent = walker.currentNode.textContent.replace(/hello/, `world`);
}
}
getANode();