samedi 26 mars 2016

Checkbox -cross out the text when clicking checkBox for a todo list

Ive been watching a tutorial on how to cross out the text when clicking on the checkbox next to the text and my code doesn't work- even though its the same as in the tutorial (where it works just fine). Ive been looking at my code for so long but can't see whats wrong-maybe its just a typo I can't see-anyone knows why?

Here is the javascript code (just the relevant part)

function updatingItem() {

var cbId = this.id.replace("cb_", "");
var textItem = document.getElementById("item_" + cbId);
textItem.style.textDecoration = "line-through";
}

function addItem() {
totalItems++;
var entry = document.createElement("li");
var checkBox = document.createElement("input");
checkBox.type = "checkbox";
checkBox.id = "cb_" + totalItems;
checkBox.onclick = updatingItem;

var span = document.createElement("span");
span.id = "item_" + totalItems;
span.innerHtml = textItem;

var textItem = document.getElementById("textItem");
entry.innerText = textItem.value;
var location = document.getElementById("todoList");

entry.appendChild(checkBox);
entry.appendChild(span);
location.appendChild(entry);

}




Aucun commentaire:

Enregistrer un commentaire