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 clearfix">
    <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>
    <section id="lists">
      <h5>Todo</h5>
      <ul id="my-todo" class="list-unstyled">
        <!-- display todos here -->
      </ul>
      <h5>Done</h5>
      <ul id="my_done" class="list-unstyled">
        <!-- display todos here -->
      </ul>
    </section>
  </div>
              
            
!

CSS

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

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

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

.fa-trash:hover {
  cursor: pointer;
}

.lists {
  float: left;
  margin-right: 15px;
  width:250px;
}
              
            
!

JS

              
                // init
let todoList = document.querySelector('#my-todo')
let doneList = document.querySelector('#my_done')
let lists = document.querySelector('#lists')

const todos = ['Hit the gym', 'Read a book', 'Buy eggs', 'Organize office', 'Pay bills']
for (let todo of todos) {
  addItem(todo)
}

function addItem(text) {
  if (text !== '') {
    let newItem = document.createElement('li')
    newItem.innerHTML = `
    <input type="checkbox" value ="${text}" name="todo_list"> <label for="todo">${text}</label>
    <i class="delete fa fa-trash"></i>
  `
    todoList.appendChild(newItem)
  }
}

function deleteItem(event) {
  let li = event.target.parentElement
  li.remove()
}

function moveItem(event) {
  let li = event.target.parentElement
  // toggle checked in lable contents
  event.target.nextElementSibling.classList.toggle('checked')
  if (event.target.parentElement.parentElement.id === 'my-todo') {
     doneList.appendChild(li)
  } else {
     todoList.appendChild(li)
  }
}

// write your code here
const addBtn = document.querySelector('#addBtn')
const inputBox = document.querySelector('.form-control')
addBtn.addEventListener('click', function (event) {
  let inputValue = document.querySelector('#newTodo').value
  addItem(inputValue)
  inputBox.value = ''
})

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

lists.addEventListener('click', function (event) {
  if (event.target.classList.contains('delete')) {
    deleteItem(event)
  } else if (event.target.tagName === "INPUT") {
    moveItem(event)
  }
})


              
            
!
999px

Console