I have a function that every time the user inserts a value in an input it adds a <li> element inside a <ul>.
that same function creates the <li> with the attribute ( onclick="doneToggle" ).
function createListElement() {
var li = document.createElement("li");
ul.appendChild(li);
li.appendChild(document.createTextNode(input.value));
li.setAttribute("onclick", "doneToggle()")
li.setAttribute("style", "width: fit-content")
input.value = "";
}
doneToggle is a function that I want to add a specific class to that element, that css class makes the text have a "line-through" style.
so far this is the function
function doneToggle(element) {
element.classList.toggle("done");
}
I want that function to retrieve that clicked element and toggle its class without having to assign IDs to the <li>'s.
Thank you in advance