How do I edit a To Do list in JavaScript?

Today we're gonna learn how to do CRUD Operations in JavaScript by making a Todo App. Let's get started πŸ”₯

This is the app we're making today:

How do I edit a To Do list in JavaScript?

  • Live preview
  • GitHub Repository

You can watch this tutorial on YouTube as well if you like πŸŽ₯

Table of Contents
  • What is CRUD?
  • Understanding CRUD Principles
  • How to Make a To-Do App using CRUD Operations

What is CRUD?

How do I edit a To Do list in JavaScript?

CRUD stands for -

  • C: Create
  • R: Read
  • U: Update
  • D: Delete

How do I edit a To Do list in JavaScript?

CRUD is a type of mechanism that allows you to create data, read data, edit it, and delete those data. In our case, we're gonna make a Todo app, so we will have 4 options to create tasks, read tasks, update tasks, or delete tasks.

Understanding CRUD Principles

Before starting the tutorial, first, let's understand the CRUD principles. For that, let's create a very very simple Social Media Application.

How do I edit a To Do list in JavaScript?

Setup

How do I edit a To Do list in JavaScript?

For this project, we will be following these steps below:

  • Create 3 files named index.html, style.css, and main.js
  • Link the JavaScript and CSS file to index.html
  • Start your live server

HTML

Inside the body tag, create a div with a class name

<div id="posts">
  <div>
    <p>Hello world post 1</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>

  <div >
    <p>Hello world post 2</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>
</div>
4. There, we will have 2 sections,
<div id="posts">
  <div>
    <p>Hello world post 1</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>

  <div >
    <p>Hello world post 2</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>
</div>
5 and
<div id="posts">
  <div>
    <p>Hello world post 1</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>

  <div >
    <p>Hello world post 2</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>
</div>
6 πŸ‘‡

<body>
  <h1>Social Media App</h1>
  <div class="container">

    <div class="left"></div>
    <div class="right"></div>

  </div>
</body>

On the left side, we will create our posts. On the right side, we can see, update, and delete our posts. Now, create a form inside the .left div tag πŸ‘‡

<div class="left">
  <form id="form">
    <label for="post"> Write your post here</label>
    <br><br>
    <textarea name="post" id="input" cols="30" rows="10"></textarea>
    <br> <br>
    <div id="msg"></div>
    <button type="submit">Post</button>
  </form>
</div>

Write this code inside the HTML so that we can display our post on the right side πŸ‘‡

<div class="right">
  <h3>Your posts here</h3>
  <div id="posts"></div>
</div>

Next, we'll insert the font-awesome CDN inside the head tag to use its fonts in our project πŸ‘‡

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" />

Now, we're gonna make some sample posts with delete and edit icons. Write this code inside the div with the id #posts: πŸ‘‡

<div id="posts">
  <div>
    <p>Hello world post 1</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>

  <div >
    <p>Hello world post 2</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>
</div>

The result so far looks like this:

How do I edit a To Do list in JavaScript?

CSS

How do I edit a To Do list in JavaScript?

Let's keep it simple. Write these styles inside your stylesheet: πŸ‘‡

body {
  font-family: sans-serif;
  margin: 0 50px;
}

.container {
  display: flex;
  gap: 50px;
}

#posts {
  width: 400px;
}

i {
  cursor: pointer;
}

Now, write these styles for the post div and option icons: πŸ‘‡

#posts div {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.options {
  display: flex;
  gap: 25px;
}

#msg {
  color: red;
}

The results so far look like this:πŸ‘‡

How do I edit a To Do list in JavaScript?

JavaScript Part

How do I edit a To Do list in JavaScript?

According to this flow chart, we will go forward with the project. Don't worry, I'll explain everything along the way. πŸ‘‡

How do I edit a To Do list in JavaScript?

Form Validation

First, let's target all the ID selectors from the HTML in JavaScript. Like this: πŸ‘‡

let form = document.getElementById("form");
let input = document.getElementById("input");
let msg = document.getElementById("msg");
let posts = document.getElementById("posts");

Then, build a submit event listener for the form so that it can prevent the default behaviour of our App. At the same time, we will create a function named

<div id="posts">
  <div>
    <p>Hello world post 1</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>

  <div >
    <p>Hello world post 2</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>
</div>
7. πŸ‘‡

form.addEventListener("submit", (e) => {
  e.preventDefault();
  console.log("button clicked");

  formValidation();
});

let formValidation = () => {};

Now, we're gonna make an if else statement inside our

<div id="posts">
  <div>
    <p>Hello world post 1</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>

  <div >
    <p>Hello world post 2</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>
</div>
7 function. This will help us prevent users from submitting blank input fields. πŸ‘‡

let formValidation = () => {
  if (input.value === "") {
    msg.innerHTML = "Post cannot be blank";
    console.log("failure");
  } else {
    console.log("successs");
    msg.innerHTML = "";
  }
};

Here's the result so far: πŸ‘‡

How do I edit a To Do list in JavaScript?

As you can see, a message will also show up if the user tries to submit the form blank.

How to accept data from input fields

Whatever data we get from the input fields, we will store them in an object. Let's create an object named

<div id="posts">
  <div>
    <p>Hello world post 1</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>

  <div >
    <p>Hello world post 2</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>
</div>
9. And, create a function named
body {
  font-family: sans-serif;
  margin: 0 50px;
}

.container {
  display: flex;
  gap: 50px;
}

#posts {
  width: 400px;
}

i {
  cursor: pointer;
}
0: πŸ‘‡

<div class="left">
  <form id="form">
    <label for="post"> Write your post here</label>
    <br><br>
    <textarea name="post" id="input" cols="30" rows="10"></textarea>
    <br> <br>
    <div id="msg"></div>
    <button type="submit">Post</button>
  </form>
</div>
0

The main idea is that, using the function, we collect data from the inputs and store them in our object named

<div id="posts">
  <div>
    <p>Hello world post 1</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>

  <div >
    <p>Hello world post 2</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>
</div>
9. Now let's finish building our
body {
  font-family: sans-serif;
  margin: 0 50px;
}

.container {
  display: flex;
  gap: 50px;
}

#posts {
  width: 400px;
}

i {
  cursor: pointer;
}
0 function.

<div class="left">
  <form id="form">
    <label for="post"> Write your post here</label>
    <br><br>
    <textarea name="post" id="input" cols="30" rows="10"></textarea>
    <br> <br>
    <div id="msg"></div>
    <button type="submit">Post</button>
  </form>
</div>
1

Also, we need the

body {
  font-family: sans-serif;
  margin: 0 50px;
}

.container {
  display: flex;
  gap: 50px;
}

#posts {
  width: 400px;
}

i {
  cursor: pointer;
}
0 function to work when the user clicks the submit button. For that, we will fire this function in the else statement of our
<div id="posts">
  <div>
    <p>Hello world post 1</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>

  <div >
    <p>Hello world post 2</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>
</div>
7 function. πŸ‘‡

<div class="left">
  <form id="form">
    <label for="post"> Write your post here</label>
    <br><br>
    <textarea name="post" id="input" cols="30" rows="10"></textarea>
    <br> <br>
    <div id="msg"></div>
    <button type="submit">Post</button>
  </form>
</div>
2

When we input data and submit the form, on the console we can see an object holding our user's input values. Like this: πŸ‘‡

How do I edit a To Do list in JavaScript?

How to create posts using JavaScript template literals

In order to post our input data on the right side, we need to create a div element and append it to the posts div. First, let's create a function and write these lines: πŸ‘‡

<div class="left">
  <form id="form">
    <label for="post"> Write your post here</label>
    <br><br>
    <textarea name="post" id="input" cols="30" rows="10"></textarea>
    <br> <br>
    <div id="msg"></div>
    <button type="submit">Post</button>
  </form>
</div>
3

The backticks are template literals. It will work as a template for us. Here, we need 3 things: a parent div, the input itself, and the options div which carries the edit and delete icons. Let's finish our function πŸ‘‡

<div class="left">
  <form id="form">
    <label for="post"> Write your post here</label>
    <br><br>
    <textarea name="post" id="input" cols="30" rows="10"></textarea>
    <br> <br>
    <div id="msg"></div>
    <button type="submit">Post</button>
  </form>
</div>
4

In our

body {
  font-family: sans-serif;
  margin: 0 50px;
}

.container {
  display: flex;
  gap: 50px;
}

#posts {
  width: 400px;
}

i {
  cursor: pointer;
}
5 function, we will fire our
body {
  font-family: sans-serif;
  margin: 0 50px;
}

.container {
  display: flex;
  gap: 50px;
}

#posts {
  width: 400px;
}

i {
  cursor: pointer;
}
6 function. Like this: πŸ‘‡

<div class="left">
  <form id="form">
    <label for="post"> Write your post here</label>
    <br><br>
    <textarea name="post" id="input" cols="30" rows="10"></textarea>
    <br> <br>
    <div id="msg"></div>
    <button type="submit">Post</button>
  </form>
</div>
5

The result so far: πŸ‘‡

How do I edit a To Do list in JavaScript?

So far so good guys, we're almost done with project 1.

How do I edit a To Do list in JavaScript?

How to delete a post

In order to delete a post, first of all, let's create a function inside our javascript file:

<div class="left">
  <form id="form">
    <label for="post"> Write your post here</label>
    <br><br>
    <textarea name="post" id="input" cols="30" rows="10"></textarea>
    <br> <br>
    <div id="msg"></div>
    <button type="submit">Post</button>
  </form>
</div>
6

Next up, we fire this

body {
  font-family: sans-serif;
  margin: 0 50px;
}

.container {
  display: flex;
  gap: 50px;
}

#posts {
  width: 400px;
}

i {
  cursor: pointer;
}
7 function inside all of our delete icons using an onClick attribute. You'll write these lines in HTML and on the template literal. πŸ‘‡

<div class="left">
  <form id="form">
    <label for="post"> Write your post here</label>
    <br><br>
    <textarea name="post" id="input" cols="30" rows="10"></textarea>
    <br> <br>
    <div id="msg"></div>
    <button type="submit">Post</button>
  </form>
</div>
7

The

body {
  font-family: sans-serif;
  margin: 0 50px;
}

.container {
  display: flex;
  gap: 50px;
}

#posts {
  width: 400px;
}

i {
  cursor: pointer;
}
8 keyword will refer to the element that fired the event. in our case, the
body {
  font-family: sans-serif;
  margin: 0 50px;
}

.container {
  display: flex;
  gap: 50px;
}

#posts {
  width: 400px;
}

i {
  cursor: pointer;
}
8 refers to the delete button.

Look carefully, the parent of the delete button is the span with class name options. The parent of the span is the div. So, we write

#posts div {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.options {
  display: flex;
  gap: 25px;
}

#msg {
  color: red;
}
0 twice so that we can jump from the delete icon to the div and target it directly to remove it.

Let's finish our function. πŸ‘‡

<div class="left">
  <form id="form">
    <label for="post"> Write your post here</label>
    <br><br>
    <textarea name="post" id="input" cols="30" rows="10"></textarea>
    <br> <br>
    <div id="msg"></div>
    <button type="submit">Post</button>
  </form>
</div>
8

The result so far: πŸ‘‡

How do I edit a To Do list in JavaScript?

How to edit a post

In order to edit a post, first of all, let's create a function inside our JavaScript file:

<div class="left">
  <form id="form">
    <label for="post"> Write your post here</label>
    <br><br>
    <textarea name="post" id="input" cols="30" rows="10"></textarea>
    <br> <br>
    <div id="msg"></div>
    <button type="submit">Post</button>
  </form>
</div>
9

Next up, we fire this

#posts div {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.options {
  display: flex;
  gap: 25px;
}

#msg {
  color: red;
}
1 function inside all of our edit icons using an onClick attribute. You'll write these lines in HTML and on the template literal. πŸ‘‡

<div class="right">
  <h3>Your posts here</h3>
  <div id="posts"></div>
</div>
0

The

body {
  font-family: sans-serif;
  margin: 0 50px;
}

.container {
  display: flex;
  gap: 50px;
}

#posts {
  width: 400px;
}

i {
  cursor: pointer;
}
8 keyword will refer to the element that fired the event. In our case, the
body {
  font-family: sans-serif;
  margin: 0 50px;
}

.container {
  display: flex;
  gap: 50px;
}

#posts {
  width: 400px;
}

i {
  cursor: pointer;
}
8 refers to the edit button.

Look carefully, the parent of the edit button is the span with class name options. The parent of the span is the div. So, we write

#posts div {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.options {
  display: flex;
  gap: 25px;
}

#msg {
  color: red;
}
0 twice so that we can jump from the edit icon to the div and target it directly to remove it.

Then, whatever data is inside the post, we bring it back on the input field to edit it.

Let's finish our function. πŸ‘‡

<div class="right">
  <h3>Your posts here</h3>
  <div id="posts"></div>
</div>
1

The result so far: πŸ‘‡

How do I edit a To Do list in JavaScript?

Take a Break!

How do I edit a To Do list in JavaScript?

Congratulations everyone for completing project 1. Now, take a small break!

How to Make a To-Do App using CRUD Operations

How do I edit a To Do list in JavaScript?

Let's start making project 2, which is a To-Do App.

Project Setup

How do I edit a To Do list in JavaScript?

For this project, we will be following these steps below:

  • Create 3 files named index.html, style.css, and main.js
  • Link the JavaScript and CSS files to index.html
  • Start our live server

HTML

Write this starter code inside the HTML file: πŸ‘‡

<div class="right">
  <h3>Your posts here</h3>
  <div id="posts"></div>
</div>
2

The div with an id

#posts div {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.options {
  display: flex;
  gap: 25px;
}

#msg {
  color: red;
}
5 is the button that will open the modal. The span will be displayed on the button. The
#posts div {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.options {
  display: flex;
  gap: 25px;
}

#msg {
  color: red;
}
6 is the icon from font-awesome.

We're going to use bootstrap to make our modal. We'll use the modal to add new tasks. For that, add the bootstrap CDN link inside the head tag. πŸ‘‡

<div class="right">
  <h3>Your posts here</h3>
  <div id="posts"></div>
</div>
3

To see the created tasks, we'll use a div with an id tasks, inside the div with the classname app. πŸ‘‡

<div class="right">
  <h3>Your posts here</h3>
  <div id="posts"></div>
</div>
4

Insert the font-awesome CDN inside the head tag to use fonts in our project πŸ‘‡

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" />

Copy and paste the code below which are from the bootstrap modal. It carries a form with 3 input fields and a submit button. If you want then you can search Bootstrap's website by writing 'modal' in the search bar.

<div class="right">
  <h3>Your posts here</h3>
  <div id="posts"></div>
</div>
6

The result so far: πŸ‘‡

How do I edit a To Do list in JavaScript?

We're done with the HTML file setup. Let's start the CSS.

CSS

How do I edit a To Do list in JavaScript?

Add these styles in the body so that we can keep our app at the exact center of the screen.

<div class="right">
  <h3>Your posts here</h3>
  <div id="posts"></div>
</div>
7

Let's style the div with the classname app. πŸ‘‡

<div class="right">
  <h3>Your posts here</h3>
  <div id="posts"></div>
</div>
8

The result so far: πŸ‘‡

How do I edit a To Do list in JavaScript?

Now, let's style the button with the id

#posts div {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.options {
  display: flex;
  gap: 25px;
}

#msg {
  color: red;
}
5. πŸ‘‡

<div class="right">
  <h3>Your posts here</h3>
  <div id="posts"></div>
</div>
9

The result so far: πŸ‘‡

How do I edit a To Do list in JavaScript?

If you click on the button, the modal pops up like this: πŸ‘‡

How do I edit a To Do list in JavaScript?

Add the JS

How do I edit a To Do list in JavaScript?

In the JavaScript file, first of all, select all the selectors from the HTML that we need to use. πŸ‘‡

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" />
0

Form Validations

We cannot let a user submit blank input fields. So, we need to validate the input fields. πŸ‘‡

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" />
1

Also, add this line inside the CSS:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" />
2

The result so far: πŸ‘‡

How do I edit a To Do list in JavaScript?

As you can see, the validation is working. The JavaScript code doesn't let the user submit blank input fields, otherwise you're gonna see an error message.

How to collect data and use local storage

Whatever inputs the user writes, we need to collect them and store them in local storage.

First, we collect the data from the input fields, using the function named

body {
  font-family: sans-serif;
  margin: 0 50px;
}

.container {
  display: flex;
  gap: 50px;
}

#posts {
  width: 400px;
}

i {
  cursor: pointer;
}
0 and an array named
<div id="posts">
  <div>
    <p>Hello world post 1</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>

  <div >
    <p>Hello world post 2</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>
</div>
9. Then we push them inside the local storage like this: πŸ‘‡

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" />
3

Also note that this will never work unless you invoke the function

body {
  font-family: sans-serif;
  margin: 0 50px;
}

.container {
  display: flex;
  gap: 50px;
}

#posts {
  width: 400px;
}

i {
  cursor: pointer;
}
0 inside the else statement of the form validation. Follow along here: πŸ‘‡

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" />
4

You may have noticed that the modal doesn't close automatically. To solve this, write this small function inside the else statement of the form validation: πŸ‘‡

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" />
5

If you open Chrome dev tools, go to the application and open the local storage. You can see this result: πŸ‘‡

How do I edit a To Do list in JavaScript?

How to create new tasks

In order to create a new task, we need to create a function, use template literals to create the HTML elements, and use a map to push the data collected from the user inside the template. Follow along here: πŸ‘‡

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" />
6

Also note that the function will never run unless you invoke it inside the

body {
  font-family: sans-serif;
  margin: 0 50px;
}

.container {
  display: flex;
  gap: 50px;
}

#posts {
  width: 400px;
}

i {
  cursor: pointer;
}
0 function, like this: πŸ‘‡

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" />
7

Once we're done collecting and accepting data from the user, we need to clear the input fields. For that we create a function called

let form = document.getElementById("form");
let input = document.getElementById("input");
let msg = document.getElementById("msg");
let posts = document.getElementById("posts");
2. Follow along: πŸ‘‡

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" />
8

The result so far: πŸ‘‡

How do I edit a To Do list in JavaScript?

As you can see, there's no styles with the card. Let's add some styles: πŸ‘‡

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" />
9

Style the edit and delete buttons with this code: πŸ‘‡

<div id="posts">
  <div>
    <p>Hello world post 1</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>

  <div >
    <p>Hello world post 2</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>
</div>
0

The result so far: πŸ‘‡

How do I edit a To Do list in JavaScript?

Function to delete a task

Look here carefully, I added 3 lines of code inside the function.

  • The first line will delete the HTML element from the screen,
  • the second line will remove the targetted Task from the data array,
  • and the third line will update the local storage with the new data.
<div id="posts">
  <div>
    <p>Hello world post 1</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>

  <div >
    <p>Hello world post 2</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>
</div>
1

Now create a dummy task and try to delete it. The result so far looks like this: πŸ‘‡

How do I edit a To Do list in JavaScript?

Function to edit tasks

Look here carefully, I added 5 lines of code inside the function.

  • Line 1 is targetting the task that we selected to edit
  • Lines 2, 3, and 4, are targetting the values [task, date, description] of the task that we selected to edit
  • line 5 is running the delete function to remove the selected data both from the local storage, HTML element, and data array.
<div id="posts">
  <div>
    <p>Hello world post 1</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>

  <div >
    <p>Hello world post 2</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>
</div>
2

Now, try to create a dummy task and edit it. The result so far: πŸ‘‡

How do I edit a To Do list in JavaScript?

How to get data from local storage

If you refresh the page, you'll note that all of your data is gone. In order to solve that issue, we run a IIFE (Immediately invoked function expression) to retrieve the data from local storage. Follow along: πŸ‘‡

<div id="posts">
  <div>
    <p>Hello world post 1</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>

  <div >
    <p>Hello world post 2</p>
    <span class="options">
      <i class="fas fa-edit"></i>
      <i class="fas fa-trash-alt"></i>
    </span>
  </div>
</div>
3

Now the data will show up even if you refresh the page.

Conclusion

How do I edit a To Do list in JavaScript?

Congratulations for successfully completing this tutorial. You've learned how to create a todo list application using CRUD operations. Now, you can create your own CRUD application using this tutorial.

Here's your medal for reading until the end. ❀️

Suggestions & Criticisms Are Highly Appreciated ❀️

How do I edit a To Do list in JavaScript?

  • LinkedIn/ JoyShaheb
  • YouTube / JoyShaheb
  • Twitter / JoyShaheb
  • Instagram / JoyShaheb

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT


How do I edit a To Do list in JavaScript?
Joy Shaheb

Joy is an experienced Senior Frontend Developer and a mentor based in Dhaka, Bangladesh. He is highly enthusiastic about javascript & He is on a mission to create the best web dev tutorials online


If you read this far, tweet to the author to show them you care. Tweet a thanks

Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started

How to make a todo app with JavaScript?

See the live demo..
Prerequisites. This tutorial assumes that you have a basic knowledge of JavaScript. ... .
Get started. The todo list app we'll build in this tutorial will be pretty basic. ... .
Add a todo. ... .
Render the todo items. ... .
Mark a task as completed. ... .
Delete todo items. ... .
Add an empty state prompt. ... .
A subtle bug..

How do you program a To Do list?

15 secrets for a better to-do list.
Capture everything. ... .
Lists, lists, and more lists. ... .
Organize your to-do list by workflow, priority, or due date. ... .
Make it actionable. ... .
Verbs first, details later. ... .
Prioritize your to-dos. ... .
Always include a deadline. ... .
Break big work into smaller tasks..

How do I make an editable list in HTML?

To edit the content in HTML, we will use contenteditable attribute. The contenteditable is used to specify whether the element's content is editable by the user or not. This attribute has two values. true: If the value of the contenteditable attribute is set to true then the element is editable.

How to create edit button in JavaScript?

const paragraph = document. getElementById("edit");.
const edit_button = document. getElementById("edit-button");.
const end_button = document. getElementById("end-editing");.
edit_button. addEventListener("click", function() {.
paragraph. contentEditable = true;.
paragraph. style. backgroundColor = "#dddbdb";.