Skip to content
Advertisements

JavaScript To Do List

CODEPEN:

JavaScript To Do List

Github:  https://github.com/furkangulsen98/HTML-CSS-JAVASCRIPT/tree/master/JavaScript%20To%20Do%20List


HTML CODE:

<div class="container">
        <h2>TO DO LIST</h2>
        <div id="addBox">
            <div id="plus" onclick="addBox()"></div>
            <input type="text" id="txt" class="txt" placeholder="Add to-do..."/>
        </div>

        <div id="list">
            <div class="box" id="box">
                <div class="txtBox">Örnek kutu</div>
            </div>
        </div>
    </div>

CSS CODE:

@import url('https://fonts.googleapis.com/css?family=Roboto+Condensed');
body {
    padding: 0;
    margin: 0;
    display: flex;
    height: 100vh;
    justify-content: center;
    align-items: center;
    background: #262626
}
.container{
    position: relative;
    background: linear-gradient(45deg,#69d9e2, #003da2);   
    width: 325px;
    height: 550px;
    border-radius: 7.5px;
    overflow: hidden;
}
h2 {
    display: block;
    width: 100%;
    height: 40px;
    padding: 0px;
    text-align: center;
    line-height: 40px;
    margin: 0px;
    box-shadow: 0px 3px 20px #262626;
    color: #fbfbfb;
    font-size: 20px;
    font-family: 'Roboto Condensed', sans-serif;
}
#addBox {
    position: relative;
    display: block;
    background: #003da2;
    width: 300px;
    height: 35px;
    margin: 15px auto;
    border-radius: 2px;
}
input {
    width: 250px;
    background: none;
    border: none;
    outline: none;
    font-family: 'Roboto Condensed', sans-serif;
    background: none;
    padding: 5px;
    margin-top: 3px;
    color: #fbfbfb;
    margin-left: 36px;
    font-size: 16px;
}
#txt::placeholder {
    color: #fbfbfb
}

#plus {
    position: absolute;
    width: 25px;
    height: 25px;
    cursor: pointer;
    margin: 5px 0px 5px 10px;
}
#plus::before{
    position: absolute;
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    content: "\f067";
    color: #fbfbfb;
    font-size: 24px;
    transition: .4s;
}
#plus:hover::before{
    margin-top: -3px;
    margin-left: -3px;
    font-size: 30px;
}
#list {
    width: 300px;
    height: 400px;
    margin: 10px auto;
    overflow: scroll;
}
.box {
    position: relative;
    display: block;
    width: 300px;
    overflow: scroll;
    height: 45px;
    margin: 5px 0px 5px 0px;
    background: #fbfbfb;
    opacity: .9;2;
    box-sizing: border-box;
    transition: .5s;
    max-height: 100%;
    border-radius: 3px;
}
.box::-webkit-scrollbar {
    display: none;
}
#list::-webkit-scrollbar {
    display: none;
}
.x{
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 10px;
    width: 20px;
    height: 20px;
}
.x:before{
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    content: "\f00d";
    font-size: 20px;
    color: #262626;
    cursor: pointer;
    transition: .5s;
}
.x:hover:before{
    color: #bc2626
}
.txtBox {
    font-family: 'Roboto Condensed', sans-serif;
    position: absolute;
    left: 20px;
    top: 12px;
    font-size: 17px;
}
.box.active {
    max-height: 0%;
    opacity: 0;
    margin: 0;
}
.box.checked {
    background: #b6ff00;
}

JS CODE:

    let box = document.getElementsByClassName("box");
        var i;

        for (i = 0; i < box.length; i++) {
            let x = document.createElement("DIV");
            x.setAttribute("class", "x");
            box[i].appendChild(x);
        }
        

        let Xbox = document.getElementsByClassName("x");


        function addBox() {
            let div = document.createElement("div");
            div.setAttribute("class", "box");
            div.setAttribute("id", "box");
            let txt = document.getElementById("txt").value;
            let txtNode = document.createTextNode(txt);
            let txtBox = document.createElement("div");
            txtBox.setAttribute("class", "txtBox");
            txtBox.appendChild(txtNode);
            div.appendChild(txtBox);
            

            if (txt === "") {
                alert("You can't do an empty job");
            }
            else {
                document.getElementById("list").appendChild(div);
            }
            document.getElementById("txt").value = "";

            let x = document.createElement("DIV");
            x.setAttribute("class", "x");
            box[i].appendChild(x);
            for (i = 0; i < Xbox.length; i++) {
                Xbox[i].onclick = function () {
                    this.parentElement.classList.add("active")
                }
            }

        }

        let list = document.getElementById("list");
        list.addEventListener("click", function (e) {
            if (e.target.getAttribute("class") === "box") {
                e.target.classList.toggle("checked");
            }
        },false)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: