can't for the life of me figure out why this doesn't work
document.querySelector('body').addEventListener('click', function () {
console.log('wow')
});
I dont get any error, but nothing is logged onclick.
can't for the life of me figure out why this doesn't work
document.querySelector('body').addEventListener('click', function () {
console.log('wow')
});
I dont get any error, but nothing is logged onclick.
There is no content in the body, so it has a height of 0px
. You can set its height:
document.querySelector('body').addEventListener('click', function() {
console.log('wow')
});
html,
body {
height: 100%;
}
Or attach the click
event listener to the document
instead:
document.addEventListener('click', function() {
console.log('wow')
});