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

              
                <!-- an input -->
<!-- buttons -->
<!-- show all of elements in yout todo list on the screen -->

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Vanilla Todolist</title>
        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css"
            integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">

        <style>
            body{
                font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
                background-color: #2d2d2d;
                color: white;
            }
            h1{
                margin: 50px;
            }
            ul{
                list-style-type: none;
            }
            li{
                padding: 10px;
                text-align: center;
            }
            hr{
                border-style: inset;
                border-width: 2px;
            }
            button{
                margin: 0px 10px;
                background-color: transparent;
                color: white;
                border-radius: 5px;
                border-color: white;
            }
            input{
                border-radius: 5px;
                margin-bottom: 25px;
                text-align: center;
            }
            /* ::-webkit-input-placeholder{
                text-align: center;
            } */
            #listContainer{
                margin-top: 25px;
                height:auto;
                padding: 25px 50px;
                background-color: #3c3c3c;
                border-style: solid;
                border-radius: 15px;
            }
            #notDoneDiv{
                background-color: #FF5E5E;
                min-height: 250px;
                text-decoration-color: black;
            }
            #doneDiv{
                background-color: #A2FF87;
                min-height: 250px;
                color: black;
            }
            #doneDiv button{
                color: black;
            }
        </style>        
    </head>

    <body>
        <div class = 'container'>
            <div class = 'row justify-content-center'>
                <h1>Vanilla Todolist</h1>
            </div>
            <div class='row justify-content-center'>
                <input id = "inputText" type="text" placeholder="add a todo">
            </div>    
            <div class='row justify-content-center' style="padding-top:25px">
            <button id = "addButton">Add</button>
                <button id = "removeAllButton">Remove All</button>
                <button id = "removeNotDoneButton">Remove Not Done Items</button>
                <button id = "removeDoneButton">Remove Done Items</button>
            </div>
            <div id = "listContainer">
                <div class = 'row'>
                    <div class = 'col-5 justify-content-center'> 
                        <h2 class= "text-center">NOT DONE</h1>
                    </div>
                    <div class = 'col-2 justify-content-center'></div>
                    <div class = 'col-5 justify-content-center'> 
                        <h2 class= "text-center">DONE</h1>
                    </div>
                </div>
                <div class = 'row'>
                    <div class = 'col-5 justify-content-center' id = 'notDoneDiv'>
                        <ul class = 'row justify-content-center' id = "notDoneUl">
                        </ul>
                    </div>
                    <div class = 'col-2 justify-content-center'></div>
                    <div class = 'col-5 justify-content-center'  id = 'doneDiv'>
                        <ul class = 'row justify-content-center' id = "doneUl">
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <script src="script.js"></script>
    </body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                let inputText = document.getElementById("inputText");
let addButton = document.getElementById("addButton");
let removeDoneButton = document.getElementById("removeDoneButton");
let removeNotDoneButton = document.getElementById("removeNotDoneButton");
let removeAllButton = document.getElementById("removeAllButton");
let todoUl = document.getElementById("notDoneUl");
let doneUl = document.getElementById("doneUl");
const notDoneButtonString = '<hr><button class = "edit">edit</button><button class = "toggle">toggle</button><button class = "done">set done</button><button class = "delete">delete</button>';
const doneButtonString = '<hr><br><button class = "edit">edit</button><button class = "toggle">toggle</button><button class = "notDone">set not done</button><button class = "delete">delete</button>';
let todoList = [];
let doneList = [];


window.addEventListener("keydown", function (event) {
    if (event.key == 'Enter') {
        addButton.click();
    }
}, true);

addButton.addEventListener("click", addTodo);

function addTodo() {
    if (inputText.value) {
        addToDoList(inputText.value);
        addTodoDOM();
        inputText.value = "";
    }
    else {
        alert("Do not submit an empty Todo");
    }
}

function addNotDone(notDoneItem) {
    addToDoList(notDoneItem);
    addTodoDOM();
}

function addToDoList(todo) {
    todoList.push(todo);
    console.log(todoList);
}

function addTodoDOM() {
    if (todoUl) {
        todoUl.innerHTML = " ";
    }
    todoList.forEach((todo, index) => {
        let liItem = document.createElement("li")
        liItem.innerHTML = `${todo} ${notDoneButtonString}`;
        liItem.id = index;
        liItem.className = "notDoneItem col-auto justify-content-center"
        todoUl.appendChild(liItem);
    })
}

function addDone(doneItem) {
    addDoneList(doneItem);
    addDoneDOM();
    reload();
}

function addDoneList(done) {
    doneList.push(done)
}

function addDoneDOM() {
    if (doneUl) {
        doneUl.innerHTML = " ";
    }

    doneList.forEach((done, index) => {
        let liItem = document.createElement("li")
        liItem.innerHTML = `${done} ${doneButtonString}`;
        liItem.id = index;
        liItem.className = "doneItem col-auto justify-content-center"
        doneUl.appendChild(liItem);
    })
}


function reload() {
    if (doneUl) {
        doneUl.innerHTML = " ";
        doneList.forEach((done, index) => {
            let liItem = document.createElement("li")
            liItem.innerHTML = `${done} ${doneButtonString}`;
            liItem.id = index;
            liItem.className = "doneItem col-auto justify-content-center"
            doneUl.appendChild(liItem);
        })
    }



    if (todoUl) {
        todoUl.innerHTML = " ";
        todoList.forEach((todo, index) => {
            let liItem = document.createElement("li")
            liItem.innerHTML = `${todo} ${notDoneButtonString}`;
            liItem.id = index;
            liItem.className = "notDoneItem col-auto justify-content-center"
            todoUl.appendChild(liItem);
        })
    }


}


removeAllButton.addEventListener("click", removeAll)

function removeAll() {
    todoList.splice(0, todoList.length);
    if (todoUl) {
        todoUl.innerHTML = " ";
    }

    doneList.splice(0, doneList.length);
    if (doneUl) {
        doneUl.innerHTML = " ";
    }
}


removeNotDoneButton.addEventListener("click", removeNotDoneItems);

function removeNotDoneItems() {
    todoList.splice(0, todoList.length);
    if (todoUl) {
        todoUl.innerHTML = " ";
    }

}

removeDoneButton.addEventListener("click", removeDoneItems);

function removeDoneItems() {
    doneList.splice(0, doneList.length);
    if (doneUl) {
        doneUl.innerHTML = " ";
    }
}


todoUl.addEventListener('click', checkFunction);
doneUl.addEventListener('click', checkFunction);

function checkFunction(e) {
    if (e.target.parentNode.id != null) {
        console.log(e.target.classList);
        if (e.target.classList.contains("edit")) {
            editTodo(e)
        }
        else if (e.target.classList.contains("toggle")) {
            toggleTodo(e);
        }
        else if (e.target.classList.contains("done")) {
            setDoneTodo(e);
        }
        else if (e.target.classList.contains("notDone")) {
            setNotDone(e);
        }
        else if (e.target.classList.contains("delete")) {
            removeItem(e);
        }
    }

}

//Edit

function editTodo(e) {
    let parentId = e.target.parentNode.id;
    let newInput = window.prompt("Enter new to do", "new todo task");
    todoList[parentId] = newInput;
    document.getElementById(parentId).innerHTML = `${newInput} ${notDoneButtonString}`;
}

//Toggle

function toggleTodo(e) {
    let parentId = e.target.parentNode.id;
    if (document.getElementById(parentId).style.textDecoration == "line-through") {
        document.getElementById(parentId).style.textDecoration = "none";
    }
    else {
        document.getElementById(parentId).style.textDecoration =" line-through";
    }
}

function setNotDone(e) {
    let parentId = e.target.parentNode.id;
    addNotDone(doneList[parentId]);
    removeItem(e);
}

function setDoneTodo(e) {
    let parentId = e.target.parentNode.id;
    addDone(todoList[parentId]);
    removeItem(e);
}

//Delete

function removeItem(e) {
    let parentId = e.target.parentNode.id;
    if (e.target.parentNode.classList.contains("notDoneItem")) {
        console.log("went into not done");
        todoList.splice(parentId, 1);
    }
    else if (e.target.parentNode.classList.contains("doneItem")) {
        console.log("went into done");
        doneList.splice(parentId, 1);
    }
    reload();

    console.log("Todo List: " + todoList)
    console.log("Done List: " + doneList)
}
              
            
!
999px

Console