javascript - Null in not an object (evaluation itemText.style) -
in to-do list, trying strike through item checked off, receiving error - "null in not object (evaluating 'itemtext.style')"
can explain how should alter make strike-through work? i'm trying avoid putting css in html file, if possible.
function removeitem() { var boxid = this.id.replace("boxid_", ""); var itemtext = document.getelementbyid("item_", + boxid); itemtext.style.setproperty("text-decoration", "line-through"); //error here } function addnewitem(list, itemtext) { totalitems++; var listitem = document.createelement("li"); var checkbox = document.createelement("input"); checkbox.type = "checkbox"; checkbox.id = "cb_" + totalitems; var span = document.createelement("span"); span.id = "item_" + totalitems; span.innertext = itemtext; checkbox.onclick = removeitem; listitem.appendchild(checkbox); listitem.appendchild(span); list.appendchild(listitem); } var btnnew = document.getelementbyid("btnadd"); var totalitems = 0; var initemtext = document.getelementbyid("initemtext"); initemtext.focus(); btnnew.onclick = function() { var itemtext = initemtext.value; if (!itemtext || itemtext == "") { return false; } addnewitem(document.getelementbyid("todolist"), itemtext); };
it because of line
var itemtext = document.getelementbyid("item_", + boxid);
there comma after closing quotes. code ignored boxid
since taken parameter getelementbyid
ignored.
make it
var itemtext = document.getelementbyid("item_" + boxid);
Comments
Post a Comment