N
N
Norum2021-07-01 16:44:01
JavaScript
Norum, 2021-07-01 16:44:01

What are the subtle differences between toggleClass and addClass and removeClass?

It is clear that toggleClass works like a class switch, and addClass only adds a class, and removeClass removes, but what are the subtleties of using these methods? When should one be used and when should the other?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Ineshin, 2021-07-01
@Norum

toggle is an abstraction over successive calls to add-remove-add-remove...
It is used only in rare cases when it is known to always change the value to the opposite.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question