I have such a JavaScript
const checkBox = document.createElement("input")
checkBox.className = "form-check-input me-1 fa-pull-right"
checkBox.type = "checkbox"
li.appendChild(checkBox);
checkBox.id = "checkBox";
checkBox.addEventListener('change', function(e) {
if (checkBox.checked) {
li.setAttribute = ("id", "completed");
} else
li.removeAttribute = ("id", "completed");
});
code to create an input and when its checked add a style id tag to add line through but i am getting this error.
Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')"
Some of the issues with your code are:
liis not defined or declared.setAttributeis a function and not an assignment, it cannot be used with equal signs.lielement is required within the DOM to append.I have made the following changes to address the issues in your code:
var lideclaration.lielement within the HTML for appending.completedwill be added to thelielement.