JSFiddle - React, Tailwind, and code Playground

by Yerko Palma

HTML

<div class="container">
      <p>
        <label for="new-task">Add Item</label>
        <input id="new-task" type="text">
        <button id = "addButton">Add</button>
      </p>
      
      <h3>Todo</h3>
      <ul id="incomplete-tasks">
        <li>
          <input type="checkbox"><label>Pay Bills</label>
          <input type="text" value="Pay Bills">
          <button class="edit">Edit</button>
          <button class="delete">Delete</button>
        </li>
        
        <li class="editMode">
          <input type="checkbox"><label>Go Shopping</label>
          <input type="text" id="edit-task" value="Go Shopping">
          <button class="edit">Edit</button>
          <button class="delete">Delete</button>
        </li> 
      </ul>
      
      <h3>Completed</h3>
      <ul id="completed-tasks">
        <li><input type="checkbox" checked><label>See the Doctor</label><input type="text" value="See the Doctor"><button class="edit">Edit</button><button class="delete">Delete</button></li>
      </ul>
    </div>

CSS

* {
  box-sizing:border-box;
}

/* Basic Style */
body {
  background: #fff;
  color: #333;
  font-family: Lato, sans-serif;
}
.container {
  display: block;
  width: 400px;
  margin: 100px auto 0;
}
ul {
  margin: 0;
  padding: 0;
}
li * {
  float: left;
}
li, h3 {
  clear:both;
  list-style:none;
}
input, button {
  outline: none;
}
button {
  background: none;
  border: 0px;
  color: #888;
  font-size: 15px;
  width: 60px;
  margin: 10px 0 0;
  font-family: Lato, sans-serif;
  cursor: pointer;
}
button:hover {
  color: #333;
}
/* Heading */
h3,
label[for='new-task'] {
  color: #333;
  font-weight: 700;
  font-size: 15px;
  border-bottom: 2px solid #333;
  padding: 30px 0 10px;
  margin: 0;
  text-transform: uppercase;
}
input[type="text"] {
  margin: 0;
  font-size: 18px;
  line-height: 18px;
  height: 40px;
  padding: 10px;
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 6px;
  font-family: Lato, sans-serif;
  color: #888;
}
input[type="text"]:focus {
  color: #333;
}

/* New Task */
label[for='new-task'] {
  display: block;
  margin: 0 0 20px;
}
input#new-task {
  float: left;
  width: 318px;
}

input#edit-task {
  width: 236px;
}
p > button:hover {
  color: #0FC57C;
}

/* Task list */
li {
  overflow: hidden;
  padding: 20px 0;
  border-bottom: 1px solid #eee;
}
li > input[type="checkbox"] {
  margin: 0 10px;
  position: relative;
  top: 15px;
}
li > label {
  font-size: 18px;
  line-height: 40px;
  width: 237px;
  padding: 0 0 0 11px;
}
li >  input[type="text"] {
  width: 226px;
}
li > .delete:hover {
  color: #CF2323;
}

/* Completed */
#completed-tasks label {
  text-decoration: line-through;
  color: #888;
}

/* Edit Task */
ul li input[type=text] {
  display:none;
}

ul li.editMode input[type=text] {
  display:block;
}

ul li.editMode label {
  display:none;
}

JavaScript

//Добавить новое задание
$('#addButton').click(function(){
$("#incomplete-tasks").append('<li><input type="checkbox"><label>' + $('#new-task').val() + '</label><input type="text" value="'+$('#new-task').val()+'"><button class="edit">Edit</button><button class="delete">Delete</button></li>')
});

//Отобразить поде редактирования 
$("#incomplete-tasks").on("click", ".edit", function() {
  
    if ($(this).parent().hasClass("editMode")){
        var value = $(this).parent().find('input[type=text]').val();
        $(this).parent().find('label').text(value);
    }
  //отобразить поле для ввода
  $(this).parent().toggleClass('editMode');
  
   //текст лейбула = изначальному тексту поля
  var $label = $(this).parent().find('label').text();
  $(this).children().find('input[type=text]').val($label);
    
});

//Сохранить изменения 
$('.edit').on("click", function() {
  var value = $(this).parent().find('input[type=text]').val();
  $(this).parent().find('label').text(value);
    
});

//удалить задание 
$('.delete').on("click", function() {
  $(this).parent().hide();
});

var $show = $("#incomplete-tasks").children().find('label').text();