To elaborate on the title -- if I try to take a set of queried elements, and loop over them, as below:
// given an existing string, html
const doc = new DOMParser().parseFromString(html, 'text/html')
const nonSemanticAsides = [...document.querySelector('div.sidebar')]
nonSemanticAsides.forEach(e => {
e.outerHTML = `<aside>${e.innerHTML}</aside>`
})
Nothing happens. Whereas if I do this in a browser, this is mutable; the page will update, and I can get a modified HTML string out of document.body.innerHTML. (Incidentally, I can get modified results if I reassign e.innerHTML, but not if I reassign e.parentNode.innerHTML, which I tried as a workaround to the above.)
For reference, this behavior isn't in any way related to spreading this from a NodeList into an Array; a plain for loop also doesn't work, and elsewhere in the script I'm using this for (basically, scraping publicly available technical writing and writing the contents to Markdown) the same pattern as above does work for removing nodes using e.remove().
To elaborate on the title -- if I try to take a set of queried elements, and loop over them, as below:
Nothing happens. Whereas if I do this in a browser, this is mutable; the page will update, and I can get a modified HTML string out of
document.body.innerHTML
. (Incidentally, I can get modified results if I reassigne.innerHTML
, but not if I reassigne.parentNode.innerHTML
, which I tried as a workaround to the above.)For reference, this behavior isn't in any way related to spreading this from a
NodeList
into anArray
; a plainfor
loop also doesn't work, and elsewhere in the script I'm using this for (basically, scraping publicly available technical writing and writing the contents to Markdown) the same pattern as above does work for removing nodes usinge.remove()
.