Skip to content
Advertisement

Dynamically added Item doesn’t get appended the to the list

I am trying to append a list item based on the input value. However, the list item doesn’t get appended. I tried to have script tags at different points, but that doesn’t help. What am I missing?

Here is my HTML

JavaScript

Here is my JavaScript.

JavaScript

Advertisement

Answer

You need to use createElement function to create your li to do items. and then use appendChild on that – Also consider using addEventListener

I have also added a functionality of clearAll button. Which will let you clear all to do items from your list.

Also, since you are using a form in your HTML which means the default behaviour is that it will reload the page. To stop that from happening use preventDefault method.

Live Demo:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement