There is an alternative to create a DOM element that doesn't append to the body (actually the one from OP doesn't either!) :
const parser = new DOMParser() const floatingElement = parser.parseFromSrting(stringWithTags, 'text/xml') const string = floatingElement.innerText
You could also use document.createDocumentFragment(string), but fragment have no innerText, so in the end it's more complicated.
document.createDocumentFragment(string)
The method presented in the main post doesn't append to the body, either.
Ho you're right, I read that too quickly :p
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
There is an alternative to create a DOM element
that doesn't append to the body(actually the one from OP doesn't either!) :You could also use
document.createDocumentFragment(string)
, but fragment have no innerText, so in the end it's more complicated.The method presented in the main post doesn't append to the body, either.
Ho you're right, I read that too quickly :p