Skip to content
All you need to do is define your event handler function, and attach it to your HTML element inline.if(typeof __ez_fad_position != 'undefined'){__ez_fad_position('div-gpt-ad-linguinecode_com-box-3-0')}; But what about plain ol’ JavaScript event listeners? An event is a signal that something has happened. Trouvé à l'intérieur – Page 248< p > Click this document to activate the handler . ... Calling its addEventListener method registers the second argument to be called whenever the event described by its ... < button > Click me < / button > < p > No handler here . https://jsfiddle.net/r2bc6axg/ That way, the . First, we'll look at the traditional onclick style that you do right from the HTML page. documentElement.addEventListener("click", function(e) { console.log( e. target); }); This is where it gets tricky. On Firefox 38, onclick fires only on left click, but AddEventListener click fires on left, middle and right clicks. In this example, even if the user clicks right on the button somewhere, depending on exactly where they click, e.target could be: The button element. JavaScript button click and JavaScript click event explained with code examples. Konrad Traczyk 22,286 Points Konrad Traczyk . Trouvé à l'intérieur – Page 179