Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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="m-5">
    <header class="mb-3">
      <h4>My Todo</h4>
      <div class="form-inline">
        <input type="text" placeholder="add item" id="newTodo" class="form-control mr-2">
        <button id="addBtn" class="btn btn-info">Add</button>
      </div>
    </header>
    <ul id="my-todo" class="list-unstyled">
      <h2>Todo</h2>
      <!-- display todos here -->
    </ul>
    <!--     create done list -->
    <ul id="done-list" class="list-unstyled">
      <h2>Done</h2>
      <!-- display todos here -->
    </ul>
  </div>
              
            
!

CSS

              
                .checked {
  color: #ccc;
  text-decoration: line-through;
  font-style: italic;
}

.fa {
  margin: 0 5px;
  color: #bbb;
}

li>label[for='todo'] {
  width: 210px;
}

#my-todo {
  padding: 10px 20px;
  border: 1px solid #DCDCDC;
  border-radius: 5px;
}

#done-list {
  padding: 10px 20px;
  border: 1px solid #DCDCDC;
  border-radius: 5px;
/*   background-color: #DCDCDC; */
}
              
            
!

JS

              
                // init
let list = document.querySelector('#my-todo')
let done = document.querySelector('#done-list')
const todos = ['Hit the gym', 'Read a book', 'Buy eggs', 'Organize office', 'Pay bills']
for (let todo of todos) {
  addItem(todo)
}

function addItem (text) {
  let newItem = document.createElement('li')
  newItem.innerHTML = `
    <label for="todo">${text}</label>
    <i class="delete fa fa-trash"></i>
  `
  list.appendChild(newItem)
}

// Add
const addBtn = document.querySelector('#addBtn')
addBtn.addEventListener('click', function () {
  let inputValue = document.querySelector('#newTodo').value
  // add new to-do item to list without no input.
  if (inputValue !== '') {
  addItem(inputValue)    
  }
})

//-----------------------L2A15Q3-----------------------//
// Delete Todo list
list.addEventListener('click', function (event) {
  if (event.target.classList.contains('delete')) {
    let li = event.target.parentElement
    li.remove()
  } else if (event.target.tagName === 'LABEL') {
    let li = event.target.parentElement
    // create an element to done list
    let doneItem = document.createElement('li')
    doneItem.innerHTML = li.innerHTML
    // append child element
    done.appendChild(doneItem)
    doneItem.children[0].classList.toggle('checked')
    // remove the item from todo list
    li.remove()
  } 
})

// Delete Done list
done.addEventListener('click', function (event) {
  if (event.target.classList.contains('delete')) {
    let li = event.target.parentElement
    li.remove()
  } else if (event.target.tagName === 'LABEL') {
    let li = event.target.parentElement
    // create an element to todo list
    let todoItem = document.createElement('li')
    todoItem.innerHTML = li.innerHTML
    // append child element
    list.appendChild(todoItem)
    todoItem.children[0].classList.toggle('checked')
    // remove the item from done list
    li.remove()
  }
})
//-----------------------L2A15Q3-----------------------//


// enter key listener
let placeholder = document.querySelector("#newTodo")
placeholder.addEventListener('keypress', function (event) {
  let inputValue = document.querySelector('#newTodo').value
  if ( event.keyCode == 13 ) {
    if (inputValue !== '') {
    addItem(inputValue)    
    }
  }
})

              
            
!
999px

Console