Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 149875

Editing CSS through JavaScript produces left-hand assignment error

$
0
0

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.


Viewing all articles
Browse latest Browse all 149875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>