I have two dropdown lists in a table. Each of them have a class “status” and “more”.
When I try to use this class in a switch statement, it does not work. Why?
This work:
“`
window.addEventListener(“click”, (event) => {
let row = event.target.closest(‘tr’);
id = row.dataset.id
const menu = “more”
switch (menu) {
case “more”:
alert(menu)
more(id)
break;
case “new”:
status(id)
break;
}
});
But this does NOT work (the variable is not evaluated):
“`
window.addEventListener(“click”, (event) => {
let row = event.target.closest(‘tr’);
id = row.dataset.id
const menu = (event.target.classList) <—–valid result logged
switch (menu) {
case “more”:
alert(menu)
more(id)
break;
case “new”:
status(id)
break;
}
});
What am I doing wrong?