Here I have a html
<div style="width: 200px;height:200px;padding:50px;background-color: lightcyan" id="maindiv" onclick="subdiv()"></div>
And javascript function for greating a subdiv
function subdiv() {
var p = document.getElementById('maindiv');
var s = document.createElement('div');
s.setAttribute('id','subdiv');
p.appendChild(s);
var s2 = document.getElementById('subdiv');
s2.style.height = '100px';
s2.style.width = '100px';
s2.style.backgroundColor = 'green';
}
And here I want to do an event outside document.getElementById('subdiv'):
document.addEventListener('click',function() {
alert('hello world');
});
How to avoid the alert('hello world') reaction on clicking the subdiv, and how to do, that works EXACTLY ONCE in every click outside the subdiv? I like possible simple response without a jquery. https://jsfiddle.net/hx2u6j35/ Thank you.