While working on a piece of code, I came across something bothersome and couldn't find a solution even after doing some research. It's functional, but it feels redundant to have to type this.className
three times:
this.className != 'selected' ? this.className = 'selected' : this.className = 'unselected';
Eventually, I figured out a workaround..
this.className = (this.className != 'selected') ? 'unselected' : 'selected';
..but I'm curious if there's a way to achieve the same outcome with this.className
being mentioned only once, like this:
this.className = 'selected' ? 'unselected' : 'selected';
Any suggestions would be appreciated.