- addEventListener
Add event listener
examples/dom/add_event_listener.html
<button id="btn">Click me</button> <div id="display"></div> <script src="add_event_listener.js"></script>
examples/dom/add_event_listener.js
"use strict"; function clicked() { document.getElementById('display').innerHTML = 'Hello World'; } document.getElementById('btn').addEventListener('click', clicked);