August 2017
Beginner
298 pages
7h 4m
English
Well, this is one way of adding tasks, but some users prefer adding tasks directly by hitting the Enter button. For that, let's use event listeners to detect the Enter key press in the <input> element. We can also use the onchange attribute of our <input> element, but let's give event listeners a try. The best way to add event listeners to a class is to call them in the constructor so that the event listeners are set up when the class is initialized.
So, in our class, create a new function addEventListeners() and call it in our constructor. We are going to add event listeners inside this function:
constructor() { ... this.addEventListeners();} addEventListeners() { document.getElementById('addTask').addEventListener('keypress', ...Read now
Unlock full access