Vanilla [removed] Is there a way to toggle multiple CSS-classes in one statement?

后端 未结 9 1275
情深已故
情深已故 2021-01-02 07:50

I use these JavaScript-code to change classes in my script:

var toggleDirection = function() {
  group.classList.toggle(\'left-to-right\');
  group.classLis         


        
9条回答
  •  死守一世寂寞
    2021-01-02 08:07

    Assuming that myElement is a valid DOM Element, this works:

    ['right-to-left', 'left-to-right'].forEach(function(className){
      this.classList.toggle(className);
    }, myElement);
    

提交回复
热议问题