your function declaration is wrong.Yor missed closing brackets in function declaration.it will be
function adddiv(){}
use removeChild () method.
document.body.removeChild(divElement);
As functions in javascript creates own scope,The divElement is inside the private scope of adddiv function.If you want to delete you need the removeChild method defined inside adddiv function;
if you want it accessible from any where in your script,define divElement as global variable or create this variable directly on window object from within adddiv function.
window.divElement = document.createElement("div");
function adddiv() {
var divElement = document.createElement("div"); // private scope
divElement.id = "myDiv";
divElement.style='width:100px;height:100px;border:1px solid black;'
divElement.className = "myDivClass";
divElement.innerHTML = 'new div';
document.body.appendChild(divElement);
var btn=document.getElementById('btn');
btn.addEventListener('click',function(){ // if this function is defined outside it won't work because divElement will be out of its scope
document.body.removeChild(divElement);
});
}
window.addEventListener('load',adddiv);
<input type='button' value='remove' id='btn'>