Help with 'To-Do List'

Hi, I’m still fairly new to JS and have been trying to create some basic projects.

Here is my CodePen for a ‘to-do list’:

How can I make it so when the user hits ENTER on the keyboard this will trigger the ‘+’ button and add the text in the input on to the list?

Hey Aspiring_Coder,

I believe this code snippet helps you figuring it out. :slight_smile:

INPUT_FIELD.addEventListener('keypress', function (e) {
    if (e.key === 'Enter') {
      console.log("enter pressed");


Hi Dennis,

Thanks so much for your help. I’ve now come up with a solution that works using your function.

At first, “enter pressed” wasn’t logging to the console because there was some default behaviour happening beforehand. I added e.preventDefault(); and then it logged to the console.

I then replaced the console log with a function call to display the item in the list. I ended up adding an ‘onclick’ to the HTML element because I couldn’t figure out a way of triggering the other addEventListener function by pressing the ENTER key.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.