
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Create a to-do list with JavaScript
Example
Following is the code to create a to-do list −
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <body> <input type="text" placeholder="Please Enter your Task Here.." id="txtData"> <button onclick="todoList()">AddTaskToDo</button> <ul id="to_do_list"> </ul> </body> <script> function todoList() { const myTask = document.getElementById('txtData'); const addToDoList = document.getElementById('to_do_list'); let originalValue = `<li> ${myTask.value} </li>`; myTask.value = ''; addToDoList.insertAdjacentHTML('beforeend', originalValue); } </script> </html>
To run the above program, save the file name “anyName.html(index.html)”. Right click on the file and select the option “Open with Live Server” in VSCode editor −
This will produce the following output −
Now here, I am going to enter first task.
After entering the first task, click the button.
Output
This will produce the following output on console −
Again, I am entering one more task.
After clicking the button, you will get the following output −
- Related Articles
- How to create a "to-do list" with CSS and JavaScript?
- How to create a filter list with JavaScript?
- How do you create a list with values in Java?
- How to create a list grid view with CSS and JavaScript?
- How to create a dropdown list using JavaScript?
- How do you create a list in Java?
- How do I create a multidimensional list in Python?
- Java Program to create a new list with values from existing list with Function Mapper
- Java Program to create a new list with values from existing list with Lambda Expressions
- How to create HTML list from JavaScript array?
- How do you create a list from a set in Java?
- How to create a line break with JavaScript?
- How to create a filter table with JavaScript?
- How to create a countdown timer with JavaScript?
- How to create a typing effect with JavaScript?

Advertisements