Chrome Extension

document.addEventListener javascript

document.addEventListener("click", function(){
    console.log("I am clicked")
});

//OR ADD EVENT ON A PARTICULAR EVENT
var button = document.getElementById("button");
button.addEventListener("click", function() {
    console.log("I am clicked on a button");
});

If you want to add an event on an HTML element you can add that by using "addEventListener" used in javascript. List of events that can be triggered using addEventListener is as below.

'click' - To add click event on an element

'blur' - Triggers when focus out from an element

'keyup' - Trigger after releasing pressed key on applied element

'keypress' - Triggers while pressing key on applied element

Was this helpful?
0 Comments
Never leave your website again in search of code snippets by installing our chrome extension.
Open Code Manager