I am facing trouble in removing a div element that I have created with JavaScript. I call this function onclick element.
function makediv(){
var div = document.createElement('DIV');
$(div).attr('id','md');
$(div).css({"left":e.pageX,"top":e.pageY });
$("body").append(div);
}
And here how I'am trying to remove when I click somewhere else than that div. before I click somewhere else the div even showed up it just deleted at the moment it created.
window.onclick = function(event)
{
dl=$('#md');
if(event.target!=dl)
dl.remove();
}
I have also tried this one.
window.onclick = function(event)
{
if($('#md').length!=0){
dl=$('#md');
if(event.target!=dl)
dl.remove();
}
}
But this code remove div element as it is created.