I can not understand why the click does not work exactly on the body. if there was a mistake, then when clicking on the block, it would not work either ...
var bodyClick = document.body; var wrapper = document.getElementById('wrapper'); bodyClick.style.backgroundColor = 'yellow'; wrapper.addEventListener('click', function() { wrapper.style.backgroundColor = (wrapper.style.backgroundColor !== 'red') ? wrapper.style.backgroundColor = 'red' : wrapper.style.backgroundColor = 'white'; }) bodyClick.addEventListener('click', function() { bodyClick.style.backgroundColor = (bodyClick.style.backgroundColor !== 'yellow') ? bodyClick.style.backgroundColor = 'yellow' : bodyClick.style.backgroundColor = 'green'; }) <div id="wrapper">Block</div>