I'm working on a to do list. I can enter text within a field and create a new item with a checkbox, but I cannot get the checkbox to do anything. I would like to change the color of the text once the checkbox has been clicked
function todoadd() {
todoNew = new objectTodo();
}
function objectTodo() {
var todo = document.getElementById('textinput').value;
var listItem = document.createElement("li");
var checkbox = document.createElement("input")
checkbox.type = "checkbox";
listItem.appendChild(checkbox);
var itemText = document.createTextNode(todo);
listItem.appendChild(itemText);
document.getElementById('place').appendChild(listItem);
function changeColor(checkbox,itemText) {
var check = document.getElementById(checkbox);
var todoItem = document.getElementById(itemText);
if (check.checked == true) {
todoItem.style.backgroundColor="Red";
}
}
}
<title>ToDo</title>
<body>
<div id="container">
<div id="todoList">
<div id="textboxBackground">
<input type='text' id='textinput' placeholder='What do you need to do today?' />
<button type='button' id="myButton" class='button' onclick='todoadd()' value='Add to list' />Add To-do</button>
</div>
<ul id="place"></ul>
</div>
Aucun commentaire:
Enregistrer un commentaire