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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="preconnect" href="https://fonts.gstatic.com"> 
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@1,300&display=swap" rel="stylesheet">

<link rel="stylesheet" type="text/css" href="style.css">

        <title>To Do List</title> 
</head>
<body>
 <header>
<h1>My To-Do List</h1>
</header>
<form>
		
	<input type="text" class="todo-input" name="">
	<button class="todo-button" type="submit">
		Add!
	</button>
</form>

	<div class="todo-container">
		<ul class="todo-list"></ul> 
	</div>




	
<script type="text/javascript" src="script.js"></script>
  </body>
</html>
              
            
!

CSS

              
                * {


	margin: 0;
	padding: 0;
	box-sizing: border-box;
}


body{

	background-color: rgb(255, 246, 222);

	font-family:  "poppins", sans-serif; 
}	


header {

	font-size: 1.5rem;
}


header, form {

	min-height: 20vh;
	display: flex;
	justify-content: center; 
	align-items: center;
  
}

 


form input, form button {

padding: 0.5rem;
font-size: 2rem;
border: none;
background: white;
}

form button {

	margin: 1rem;
	border: solid;
	border-width: .5px;
	border-color: rgb(176, 159, 97);
	transition: all 0.3s ease;
  border-radius: 5px; 
}

form button:hover {

background: rgb(255, 199, 115);
color: white;

} 

.todo-container {
  
  display: flex; 
  justify-content: center; 
  align-items: center;
 
}

.todo-list{
  
  list-style: none; 
  min-width: 30%;
  
  
}

.todo {
  
  margin: 1.5rem; 
  background: white;
  font-size: 1.5rem; 
  display: flex;
  justify-content: space-between;
  align-items:center; 
  transition: all 1s ease; 
  
}

.todo li {
  
  flex: 1;
  
}

.trash-btn{
  
  background: rgb(245, 66, 66); 
  border: none;
  padding: 1rem; 
  cursor: pointer; 
  font-size: 1rem; 
  color: white;
}

.complete-btn {
  
  background: rgb(153, 240, 67); 
  border: none;
  padding: 1rem; 
  cursor: pointer; 
  font-size: 1rem; 
  color: white;
}

.todo-item { 
padding: 0rem 1.5rem; 
  
}

.completed {

  text-decoration: line-through;
  opacity: 0.5;
}


.fall {

  transform: translateY(8rem) rotateZ(20deg);
}








              
            
!

JS

              
                //Selectors
const todoInput = document.querySelector(".todo-input");
const todoButton = document.querySelector(".todo-button");
const todoList = document.querySelector(".todo-list");


// Event Listeners

todoButton .addEventListener('click', addTodo);
todoList .addEventListener ('click', deleteCheck);
todoList .addEventListener ('click' , doneCheck); 

// Functions

function addTodo (event) {
//Prevent form from submitting
event.preventDefault();
//Todo DIV

const todoDiv = document.createElement("div");
todoDiv.classList.add("todo"); 
// Create li
const newTodo = document.createElement("li");
newTodo.innerText = todoInput.value; 
newTodo.classList.add("todo-item");
todoDiv.appendChild(newTodo);
//Checkmark button
const compleatedButton = document.createElement("button");
compleatedButton.innerHTML =  'done';
compleatedButton.classList.add("complete-btn");
todoDiv.appendChild(compleatedButton); 
//Trash BUTTON
const trashButton = document.createElement("button");
trashButton.innerHTML = 'discard';
trashButton.classList.add("trash-btn");
todoDiv.appendChild(trashButton); 
// APPEND TO LIST
todoList.appendChild(todoDiv);

//clear todo input value
  
 todoInput.value = "";
}

//delete list item

function deleteCheck (e) {
  
  const item = e.target; 
  
  if(item.classList[0] === "trash-btn"){
    const todo = item.parentElement;
    //animation  NOT WORKING : This is breaking the code
    
todo.remove();
    }

//I want CSS to ONLY affect the li tag
if (item.classList[0] === "complete-btn"){

const todo = item.parentElement; 
todo.classList.toggle("completed")
}

   
}    



 
 




  


              
            
!
999px

Console