Assume I have a DOM tree represented by this html.
<div id="root">
<div>
<p>hoge</p>
<span>fuga</span>
</div>
<div>
<span>piyo</span>
<div>
<span>foobar</span>
</div>
</div>
</div>
If I want to replace all the <span>
s by <button>
, how could I achieve it?
const replaceElements = () => {
const page = document.getElementById("root")
const elements = document.getElementsByTagName('span');
elements.forEach(item => ???)
}