11.8 Using addEventListener to Add Event Listeners

In our original Point Tracker web page implementation, the onclick event-handler attribute worked just fine for capturing a click on the distance button and again for capturing a click on the web page as a whole. For our improved version of the Web Tracker web page, we capture not only clicking on the web page, but also pressing the delete key on the web page. When the user presses delete, the delete key’s event handler removes the most recently created point by erasing its displayed coordinates. The mouse click event and the delete key event both need to be captured, regardless of where they occur on the web page, and that means using the html element. We could add an onkeydown event-handler ...

Get Web Programming with HTML5, CSS, and JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.