Click on HTML body with JS | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Click on HTML body with JS

Fairly new to all things web. Can I change a js variable or call a function by having the user click anywhere on the body of the webpage?

11th Aug 2018, 4:00 AM
Nathan Lewis
Nathan Lewis - avatar
1 Answer
+ 3
yes //js window.onload = function(){ document.body.addEventListener('click', function(){ alert('you clicked on the body lol') }) } //Make sure that something is in the body.
11th Aug 2018, 4:28 AM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar