Is it any native function in jQuery which check for class in an element, and then add it if this class does not exist yet?
Asked
Active
Viewed 771 times
-5
-
Use `addClass()`. Or `toggleClass` if you want to remove class if already existing. – gurvinder372 Jan 03 '18 at 08:52
-
"native function in jquery" ? What does that mean ? – Denys Séguret Jan 03 '18 at 08:52
-
1This question is way too basic. Just googling "add class jquery" is the way to go, not asking SO. – Denys Séguret Jan 03 '18 at 08:53
-
See this answer: https://stackoverflow.com/a/196038/2430414 – Blundering Philosopher Jan 03 '18 at 08:56
1 Answers
1
Just call addClass(). jQuery will do the check for you. If you check on your own, you are doubling the work, since jQuery will still run the check for you.

Wolkowsky
- 68
- 1
- 6