I'm trying to create a list that when an item is clicked, the item is strike-throughed (grammar?). However, I am getting the following error: SyntaxError: invalid assignment left-hand side. I am new to web development so I am unfamiliar with the debugging process.
I originally structured my code by passing a function that would strike the item, but that did not work. For reference, the function getForm() gets input from an input box and appends it to a displayed below the input box.
function getForm() {
.
.
.
/* Append the input to the list */
var node = document.createElement("LI"); // Create a <li> node
node.setAttribute("onclick", "strikethroughItem(this.id)"; // call func on click
var textnode = document.createTextNode(task.name); // Create a text node
node.appendChild(textnode);
document.getElementById("list").appendChild(node); // Append <li> to <ul> with id="myList"
}
function strikethroughItem(id) {
document.getElementById(id).style.text-decoration = "line-through";
}
In an attempt to see if this was a problematic approach, I adjusted it to be edited directly, like so.
function getForm() {
/* Append the input to the list */
var node = document.createElement("LI"); // Create a <li> node
node.setAttribute("onclick", "document.getElementById(this.id).style.text-decoration = 'line-through'"); // call func on click
var textnode = document.createTextNode(task.name); // Create a text node
node.appendChild(textnode);
document.getElementById("list").appendChild(node); // Append <li> to <ul> with id="myList"
}
However, it produces the same error.