DEV Community

Discussion on: A Rose by any Other Name

Collapse
 
moopet profile image
Ben Sinclair

toggle CHANGES the name of the class ("firstColor") to another name ("secondColor").

tdObj.classList.toggle("secondColor") gives the td a class of secondColor if it doesn't already have one, and removes it if it's there. It doesn't have any effect on other classes, such as firstColor.