Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When you use jQuery .removeClass() does it return an error when run on an element that does not have that class?

I have four html elements that when clicked I want to have a specific class applied to. The problem is that that class is only for one of the four at any one time. I want to when one element is clicked have that class removed from the other three elements and applied to the one that was clicked. If I were to run a loop that removed that class from every single element before applying that class to the element clicked would there be an error on the elements that did not have that class?

like image 434
chromedude Avatar asked Sep 15 '25 08:09

chromedude


1 Answers

@chrome dude, no there won't be any problem. Jquery takes care of null check. If you have class it will do it otherwise it won't do it.

like image 73
kobe Avatar answered Sep 17 '25 01:09

kobe