The Monaca Cloud IDE preview works the way you want without errors.
The following error occurs when I use the actual Android device debugger.
How should I deal with it?
vartmplNode= document.getElementById("id01");
tmplNode.remove();
↓
Uncaught TypeError: Object# has no method 'remove'
monaca
There is no guarantee that the Element of DOM has the remove()
function.It's a browser problem.
The actual error is
Object#has no method 'remove'
Object has no remove function
I've been scolded for ....
If you want to delete it, you can quickly delete the child element by referring to the parent element.
If you overwrite removeChild
or textContent
·innerText
·innerHTML
with null
, the child element disappears.
Excerpts the answers of the head office SO, but it would be easier to create a function and erase it.
function removeElement(element){
element&element.parentNode&element.parentNode.removeChild(element);
}
setTimeout(function(){
removeElement( document.getElementById("goodbye"));
},1000);
<div onclick="removeElement(this)">Clickable</div>
<divid="goodbye"> Initialize </div>
© 2024 OneMinuteCode. All rights reserved.