Can I streamline the process of adding or removing a class from an element based on a variable's truthiness? Currently, my code seems overly complex:
if (myConditionIsMet) {
myEl.classList.add("myClass");
} else {
myEl.classList.remove("myClass");
}
Is there a more elegant way to achieve this, perhaps by dynamically calling the add/remove function using a conditional operator like this:
myEl.classList.{myConditionIsMet ? add('myClass') : remove('myClass')};
Note that the above is pseudocode, and I prefer a pure JavaScript solution.