Clear element.classList

前端 未结 7 1495
暗喜
暗喜 2021-02-04 23:38

element.classList is of DOMTokenList type.

Is there a method to clear this list?

7条回答
  •  闹比i
    闹比i (楼主)
    2021-02-05 00:11

    I'm not aware of a "method" in the sense of a "function" associated with classList. It has .add() and .remove() methods to add or remove individual classes, but you can clear the list in the sense of removing all classes from the element like this:

    element.className = "";
    

提交回复
热议问题