In JavaScript and JavaScript tool library for many years, I often have such reveries: when can modern browsers provide some auxiliary methods and class libraries to replace those JavaScript tool libraries, such as jQuery, let us use the browser's native method to replace the browser's native method to replace it with they. I know that the browser will definitely improve this direction, but this evolution process will not be very fast, and various browsers need to make such innovation together. Firefox browser, Google browser, especially IE, only these mainstream browsers, only these mainstream browsers It has such functions, and our desires are really realized. The good news is that one of these functions has been added to the HTML5 API: ClassList.
In the HTML5 API, there is a ClassList object on each node in the page DOM. The programmer can use the method inside to add, delete, and modify the CSS class on the node. Using ClassList, programmers can also use it to determine whether a node is given a CSS class.
Element.classListThere are many useful methods in this classlist object:
XML/HTML code Copy content to the clipboard