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

后端 未结 9 1232
情深已故
情深已故 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 07:56

    If I need to toggle multiple classes I just create an array and then iterate through it.

      var classes = [
        "red",
        "blue",
        "green",
        "purple"
      ]
    
      for (var i = 0; i < classes.length; i++){
        p.classList.toggle(classes[i])
      }
    
    

提交回复
热议问题