function tempAlert(msg,duration) { var el = document.createElement("div"); el.classList.add('success-Message') el.setAttribute("style","position:absolute;top:40%;left:20%;background-color:white;"); el.innerHTML = msg; setTimeout(function(){ el.parentNode.removeChild(el); },duration); document.body.appendChild(el); console.log("jnk"); } tempAlert("close",5000);