After searching the MDN website, W3chools, and running tests in my browser and measurethat, I discovered some interesting things about the 3 methods. As they vary in speed and functionality, I set up a post to be able to explain how I got back in my account .. Below is a summary of it
Performance
I decided to search to know the best option. According to the site link , someone had already asked themselves the same. They did the following test I rode on Chrome, Edge and Firefox:
1st place: className
2nd place: setAttribute (except Edge)
3rd place: classList
* Result in operations per second
In practice
Even though it is very clear, the above test is not absolute, we must take into account other factors such as manipulation, functionalities and good practices.
className: Allows the manipulation of the classes in the format string, in this case having a string with all the classes written inside and allowing the manipulation of the data in this format. Because it is an old functionality, it is used by several browsers
setAttribute: The set attribute simply does this, sets the value within an attribute. There is a getAttribute that allows you to view this value, but manipulation is limited to that.
classList: Places classes within a list to be handled in an orderly fashion through a number of specific methods. The functionality level is the most practical, but in addition to having a lower performance, it has not been implemented in older browsers.
Conclusion
I believe that the className and classList are the best candidates. If you need performance and are just setting and deleting classes, use className. Now if you have a system that needs to search for classes inside the tag or add only if it does not exist, spare the effort to create a logic for it and use the classList.
For the full version of this answer, see the post: link