I'm trying to add a class to an element after an event listener detects a click of said element, I've used the following code, but it's not specific and any element being clicked will receive the class.
document.addEventListener('click', (event) => {
event.target.classList.add("selected");
});
what I thought would work was this:
var element = document.getElementById("object1");
document.element.addEventListener('click', (event) => {
element.classList.add("selected");
});
Is there anything else I can use?