14
I’m making an application and I came up with a question:
How do I remove an element from a javascript page without using innerHTML = ''
?
For example, I want to remove a div (like the example below) and all its content:
<div id="conteudo">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
How could I do this with pure Javascript?
I put the link to the English version of the Node.removeChild documentation on the Mozilla Developer Network.
– Onilton Maciel
What’s the difference between using this code you gave me and this: Document.getElementById('content'). remove() ?
– Odair
The method removes() NAY is supported by all browsers https://developer.mozilla.org/en-US/docs/Web/API/ChildNode.remove#Browser_compatibility In this list you can see that Internet Explorer and Safari nay support this method. Depending on what your application does and the clients in it, this can cause you many problems in the future.
– Onilton Maciel
Thanks for clarifying, I will use this example you suggested and give a study about
– Odair