Here is the API for the .toggleClass() method of the Jquery library. I am unsure about how to implement the switch portion. Is the switch portion supposed to result in boolean value, and if it is, then it is either implemented or not?
So if the code was :
`$('selector').toggleClass('class-to-be-toggled' , ($(this).hasClass('white')))`
and the ($(this).hasClass('white')) evaluated to true, then the .toggleClass() would execute, and if it evaluate to false, then the .toggleClass() would not execute?
Or am i misunderstanding the purpose of switch.
If you omit the parameter, the class will be added or removed depending on whatever it currently isn’t. If you pass the parameter, the class will be added or removed depending on the parameter, regardless of the current state of the element.
For instance, this:
is pretty much just a shorthand of writing:
You might object that most of the time you’d get away well with just
which may well be the case, but if anything else than the checking of a checkbox may interfere with the
selectedclass, then your toggling would be at risk of going out of sync, if you don’t pass a parameter specifying exactly what you want it to do.