0

I'm trying to build my first JavaScript application but I have a problem here. when I'm inserting an HTML from JS Using insertAdjacetHTML and I but a ${toDo} inside the HTML code it's dealing with it as a string, not a parameter! I did not know what to do here!

// display date

let today = new Date();
let options = {day: "numeric" ,weekday: "long", month: "short"}

document.getElementById('date').innerHTML = today.toLocaleDateString("en-US" , options);



// enter the todo


function addToDo(toDo) {
    let list = document.getElementById("list");
    let item = '<li class="item"><i class="fa fa-circle-thin co" job="complete" id="0"></i><p class="text"> ${toDo}</p><i class="fa fa-trash-o de" job="delete" id="0"></i></li>';

    list.insertAdjacentHTML("beforeend", item);
}

addToDo("Hi");
body{
    padding: 0;
    margin: 0;
    background-color: rgba(0,0,0,0.1);
    font-family: 'Titillium Web', sans-serif;
}

/* ------------ container ------------ */
.container{
    padding:10px;
    width:380px;
    margin:0 auto;
}

/* ------------ header ------------ */
.header{
    width: 380px;
    height:200px;
    background-image: url('../img/bg2.jpg');
    background-size: 100% 200%;
    background-repeat: no-repeat;
    border-radius: 15px 15px 0 0;
    position: relative;
}
.clear{
    width : 30px;
    height: 30px;
    position: absolute;
    right:20px;
    top: 20px;
}
.clear i{
    font-size: 30px;
    color: #FFF;
}
.clear i:hover{
    cursor: pointer;
    text-shadow: 1px 3px 5px #000;
    transform: rotate(45deg);
}
#date{
    position: absolute;
    bottom: 10px;
    left: 10px;
    color: #FFF;
    font-size: 25px;
    font-family: 'Titillium Web', sans-serif;
}

/* ------------ content ------------ */
.content{
    width:380px;
    height: 350px;
    max-height:350px;
    background-color: #FFF;
    overflow: auto;
}
.content::-webkit-scrollbar { 
    display: none; 
}
.content ul{
    padding:0;
    margin:0;
}
.item{
    width:380px;
    height: 45px;
    min-height: 45px;
    position: relative;
    border-bottom: 1px solid rgba(0,0,0,0.1);
    list-style: none;
    padding: 0;
    margin: 0;
}
.item i.co{
    position: absolute;
    font-size: 25px;
    padding-left:5px;
    left:15px;
    top:10px;
}
.item i.co:hover{
    cursor: pointer;
}
.fa-check-circle{
    color:#6eb200;
}
.item p.text{
    position: absolute;
    padding:0;
    margin:0;
    font-size: 20px;
    left:50px;
    top:5px;
    background-color: #FFF;
    max-width:285px;
}
.lineThrough{
    text-decoration: line-through;
    color : #ccc;
}
.item i.de{
    position: absolute;
    font-size: 25px;
    right:15px;
    top:10px;
}
.item i.de:hover{
    color:#af0000;
    cursor: pointer;
}
/* ------------ add item ------------ */
.add-to-do{
    position: relative;
    width: 360px;
    height:40px;
    background-color: #FFF;
    padding: 10px;
    border-top: 1px solid rgba(0,0,0,0.1);
}
.add-to-do i{
    position: absolute;
    font-size: 40px;
    color: #4162f6;
}

.add-to-do input{
    position: absolute;
    left: 50px;
    height: 35px;
    width: 310px;
    background-color: transparent;
    border: none;
    font-size: 20px;
    padding-left:10px;
}
.add-to-do input::-webkit-input-placeholder { /* Chrome/Opera/Safari */
    color: #4162f6;
    font-family: 'Titillium Web', sans-serif;
    font-size: 20px;
}
.add-to-do input::-moz-placeholder { /* Firefox 19+ */
    color: #4162f6;
    font-family: 'Titillium Web', sans-serif;
    font-size: 20px;
}
.add-to-do input:-ms-input-placeholder { /* IE 10+ */
    color: #4162f6;
    font-family: 'Titillium Web', sans-serif;
    font-size: 20px;
}
.add-to-do input:-moz-placeholder { /* Firefox 18- */
    color: #4162f6;
    font-family: 'Titillium Web', sans-serif;
    font-size: 20px;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ToDo</title>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Titillium+Web">
</head>

<body>
    <div class="container">
        <div class="header">
            <div class="clear">
                <i class="fa fa-refresh"></i>
            </div>
            <div id="date"></div>
        </div>
        <div class="content">
            <ul id="list">
            </ul>
        </div>
        <div class="add-to-do">
            <i class="fa fa-plus-circle"></i>
            <input type="text" id="input" placeholder="Add a to-do">
        </div>
    </div>

</body>

</html>

1 Answers1

1

You are using the wrong quotation mark. it's not ' it's ` .

Please also make sure that you are not using old browsers, I don't think that syntax is supported on older browsers, ( unless you are using transpilers ).

tsamridh86
  • 1,480
  • 11
  • 23