When a button is clicked, I want to add an element to my DOM. But first, I want to remove the previous one I added (in the previos click).
Inside the click handler I wrote:
document.getElementById("myId").remove();
var myP = document.createElement("p");
myP.setAttribute("id","myId");
myP.innerHTML = "asdf";
document.getElementById("myDiv").appendChild(myP);
but it's not working, the "p" does not get added to the DOM.
note: I want to use only javaScript, and I want to use "remove()" and not innerHTML = "".
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…