Is there a way to use the trigger element (in that case the div with the "container" class) in the event callback function without another dom access?
When clicking on the round dot e.target = "round-btn"
so e.target
isn't an option here.
document.getElementsByClassName("container")[0].onclick = (e) => toggleSearchFilter(e);
function toggleSearchFilter(e) {
e.target.classList.toggle("crossed-out");
}
.container {
cursor: pointer;
display: flex;
align-items: center;
user-select: none;
}
.round-btn {
width: 10px;
height: 10px;
border-radius: 50%;
margin-right: 5px;
background-color: black;
}
.crossed-out{
text-decoration: line-through;
}
<div class="container"><div class="round-btn"></div>Hello</div>