This is my first post here in Stack Overflow. Apologies if I'm not doing it in the right way.
OK so I'm doing this To Do List as a second project but I can't find a solution yet.
I tried creating a node list, then going through the whole list, creating a new element and adding it to every item. Problem is, only the icon I added to the first LI in the HTML file is showing.
Am I doing it in the wrong way?
Any help is really appreciated!
This is how it looks like so far
HTML:
<title>To Do List</title>
</head>
<body>
<div id="box">
<div id="header">
<h1 id="title">To Do List</h1>
<span onclick="newElement()" id="addButton">+</span>
<input type="text" id="newTask" class="hideMe" class="showMe" placeholder="New task...">
</div>
<div id="tasks">
<ul id="items">
<li class="checked">Go to the gym</li>
<button class="remove" class="hideMe" class="showMe"><i class="fa fa-trash"></i></button>
<li>Keep studying web development</li>
<li>1</li>
</ul>
</div>
</div>
<script src="js/toDoList.js"></script>
</body>
CSS:
ul li {
font-weight: 300;
color: white;
cursor: pointer;
transition: 0.2s;
list-style-type: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
display: inline-block;
vertical-align: top;
width: 55%;
font-size: 35px;
margin-left: 20px;
margin-bottom: 25px;
}
ul li:hover {
color: gray;
}
ul li.checked {
text-decoration: line-through;
}
.remove {
float: right;
margin-right: 0.5em;
font-size: 45px;
color:rgb(255, 66, 66);
background-color: rgba(255,255,255,0);
border: none;
transition: all 0.2s;
outline: none;
cursor: pointer;
}
.remove:hover {
color:rgba(255, 66, 66, 0.589);
}
#addButton {
font-size: 50px;
text-align: center;
cursor: pointer;
font-weight: 900;
transition: all 0.3s;
color: rgb(255, 115, 0);
background-color: rgb(225, 236, 255);
border-radius: 50%;
margin-top: 30px;
margin-right: 35px;
padding: 2px 18px 5px 18px;
user-select: none;
float: right;
}
#addButton:hover {
background-color: rgba(225, 236, 255, 0.705);
color: rgba(255, 115, 0, 0.678);
}
#box {
min-width: 10em;
max-width: 75em;
height: auto;
margin: auto;
border-radius: 25px;
background-color: rgba(70, 96, 180, 0.877);
flex-grow: .67;
object-position: center;
padding-bottom: 1em;
}
#items {
margin-top: 2em;
margin-left: 1em;
}
#newTask {
color: rgb(255, 115, 0);
font-size: 30px;
width: 100%;
height: 3em;
background-color: rgb(225, 236, 255);
outline: none;
border: none;
border-radius: 0;
display: inline-block;
}
#title {
color: rgb(255, 115, 0);
font-weight: bold;
font-size: 50px;
margin-left: 35px;
display: inline-block;
}
JS:
const addButton = document.getElementById("addButton");
const newTaskInput = document.getElementById("newTask")
const removeButton = document.getElementsByClassName("remove");
var myNodeList = document.getElementsByTagName("LI");
function main() {
for (let i = 0; i < myNodeList.length; i++) {
let span = document.createElement("SPAN")
span.className = "remove";
span.appendChild(removeButton);
myNodeList[i].appendChild(span);
}
}
main();
question from:
https://stackoverflow.com/questions/65835413/how-can-i-make-appear-a-remove-button-on-every-li-in-a-todo-list