Javascript examples for DOM:Document addEventListener
The document.addEventListener() method attaches an event handler to the document.
document.addEventListener(event, function, useCapture)
Parameter | Description |
---|---|
event | Required. name of the event. |
function | Required. function to run when the event occurs. |
useCapture | Optional. whether the event should be executed in the capturing or in the bubbling phase. |
Possible values for useCapture:
No return value
The following code shows how to Attach a click event to the document.
<!DOCTYPE html> <html> <body> <script> document.addEventListener("click", function(){ document.body.style.backgroundColor = "red"; });// w ww . ja v a 2 s .c o m </script> </body> </html>