Assign the "onclick" event to the window object: - Javascript DOM Event

Javascript examples for DOM Event:onclick

Description

Assign the "onclick" event to the window object:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>Click anywhere in this window to change the background color of body.</p>

<script>
window.onclick = myFunction;/*  w  w  w.j  a va 2s. c  om*/

function myFunction() {
    document.getElementsByTagName("BODY")[0].style.backgroundColor = "yellow";
}
</script>

</body>
</html>

Related Tutorials