Those. look, i have, let's say div. Type:

<div class='pervyui'></div> 

And the chip, if the class is equal to this, then you need to change to another. If different, then this one. So, I write this:

 function smena(obj) { if (obj.ClassName=='pervuyi') { obj.ClassName='vtoroi'; } else { obj.ClassName='pervuyi'; } } 

In general, he wrote it in different ways. Tried with two "=" signs, but nothing works. Tell me how it is correct.

And, tried to call function so:

 <div OnClick='smena(this)' class='pervyui'></div> 
  • one
    .classList.remove () /. add ()? A class is an attribute which contains not one class but a list of classes and you must treat it accordingly. - zb '

1 answer 1

The property is called "className", it is important.