Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
   <div class="container">

      <div class="todo_list">
         <h1>ToDo list</h1>
         <div class="create_new_todo">
            <input type="text" class="name" placeholder="name">
            <input type="text" class="message" placeholder="message">
            <button class="add">ADD</button>
         </div>

         <div class="wrapper">
            <ul class="todo"></ul>
         </div>

      </div>

   </div>

   <script src="./script.js"></script>
              
            
!

CSS

              
                body {
  background-color: #ffd78a;
  font-family: sans-serif;
  -webkit-box-sizing: content-box;
  box-sizing: content-box;
}

.container {
  margin: 0 auto;
  padding-top: 50px;
}

.important {
  font-weight: bold;
  color: #a40e11;
}

.todo_list {
  max-width: 400px;
  display: block;
  margin: 0 auto 40px;
  background-color: #1ba39c;
  padding: 30px;
  border-radius: 10px;
  -webkit-box-shadow: 0 2px 10px 0 #074b83;
  box-shadow: 0 2px 10px 0 #074b83;
}

h1 {
  text-align: center;
  margin-top: 0;
  margin-bottom: 20px;
  color: #fff;
  font-size: 30px;
}

.create_new_todo {
  text-align: center;
}

input[type="text"] {
  width: 376px;
  padding: 10px;
}

button {
  margin-top: 10px;
  width: 400px;
  padding: 10px;
  cursor: pointer;
}

.todo {
  padding-left: 0;
}
.todo li {
  list-style-type: none;
}
.todo li:not(:last-child) {
  border-bottom: 1px solid #000;
}

input[type="checkbox"] {
  opacity: 0;
  position: absolute;
}

input[type="checkbox"],
label {
  display: inline-block;
  vertical-align: middle;
  margin: 5px;
  cursor: pointer;
}

input[type="checkbox"] + label:before {
  content: "";
  background: #1ba39c;
  border-radius: 5px;
  border: 2px solid #ddd;
  display: inline-block;
  vertical-align: middle;
  width: 10px;
  height: 10px;
  padding: 2px;
  margin-right: 10px;
  text-align: center;
}

input[type="checkbox"]:checked + label:before {
  content: "";
  display: inline-block;
  width: 1px;
  height: 5px;
  border: solid blue;
  border-width: 0 3px 3px 0;
  transform: rotate(45deg);
  -webkit-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  border-radius: 0;
  margin: 0 15px 5px 5px;
}

              
            
!

JS

              
                const addMessage = document.querySelector('.message');
const addName = document.querySelector('.name');
const addButton = document.querySelector('.add');
const todo = document.querySelector('.todo');
const remove = document.querySelector('.remove');

let todoList = [];

function uniqueId() {
  return Math.random().toString(16).slice(2);
}

// a function to update the storage
// and update the displayed list
function updateTodoList (todoList) {
  localStorage.setItem('todo-list', JSON.stringify(todoList));
  displayMessages(todoList);
}

if (localStorage.getItem('todo-list')) {
   todoList = JSON.parse(localStorage.getItem('todo-list'));
   displayMessages(todoList);
}

addButton.addEventListener('click', function () {
  // use or '||' instead of '+'
  if (!addMessage.value || !addName.value) return;

  const newTodo = {
    id: uniqueId(),
    name: addName.value,
    message: addMessage.value,
    checked: false,
    important: false
  };

  addMessage.value = '';
  addName.value = '';

  todoList.push(newTodo);
  updateTodoList(todoList);
});

function removeMessage (id) {
  // iterate through the existing todoList
  // and using filter remove the todo that has an id
  // matching the todo we clicked delete on
  todoList = todoList.filter(
    function(todo) {
      // only return the ones that don't match
      return todo.id !== id;
    }
  )
  
  updateTodoList(todoList);
}

function displayMessages(todoList = []) {

  // Iterate through each todo with map.
  // For each todo return the list item HTML
  const messages = todoList.map(
    function(todo) {
      return `
      <li id="${todo.id}">
        Name:${todo.name}
        Message:${todo.message}
        <button class="remove" onClick="removeMessage('${todo.id}')">DELETE</button>
        <button class="edit">EDIT</button>
      </li>
      `;
    }
  );
  
  // join the array items into one big string
  // using a newline as a separator.
  todo.innerHTML = messages.join('\n');
}
              
            
!
999px

Console