SoFunction
Updated on 2025-04-07

setAttribute and class conflict resolution

Suppose, how should we write when we want to use setAttribute to change a dom class?
   1. setAttribute("class","red")
   2. setAttribute("className","red")

The answer is:
Option 1. Use under firefox
Option 2. Use under IE

If you use IE Developer to setAttribute("class") to look at the structure, you will find that two classes are displayed on the DOM... It turns out that IE distinguishes the customized class from the system class. - -b