+ 3
How can someone add events to a dom object?
3 Respuestas
+ 2
elemen . addEventListener("click",function(event){
codes});
0
Just write the JS code and specify the dom object by id or class or tag
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);
}