+ 3

How can someone add events to a dom object?

13th Dec 2016, 4:30 PM
damilare lamidi
damilare lamidi - avatar
3 Answers
+ 2
elemen . addEventListener("click",function(event){ codes});
13th Dec 2016, 5:22 PM
Sandeep Chatterjee
0
Just write the JS code and specify the dom object by id or class or tag
13th Dec 2016, 5:18 PM
Rishi Anand
Rishi Anand - avatar
0
Suppose that you have a button with id="btn", here we get the element and add eventlisteners to it: var btn = document.getElementById("btn"); btn.addEventListener("click", doOnClick); function doOnClick() { //do something //and remember to remove the event listeners from the button btn.removeEventListeners("click", doOnClick); }
18th Feb 2017, 4:46 PM
Elvis Peace Ndahayo Rugero
Elvis Peace Ndahayo Rugero - avatar