Why does removeClass() not act on the inner element?
By : Amanda Lopez
Date : July 31 2020, 08:00 PM
I hope this helps . The issue is because .closeX is a child of .menu. This means that when you click .closeX the class is removed. However the event bubbles up the DOM to .menu which then adds the class back on again. To fix this call stopPropagation() on the inner event handler:
Should I check if an element hasClass() before I removeClass()?
By : user1631284
Date : March 29 2020, 07:55 AM
this one helps. The call to removeClass() doesn't throw any errors if the class is not present on the element(s), so there really is no need to call hasClass() first. It just causes additional overhead. When asking about performance though, the calls to getClass() and removeClass() are likely to be fast. It's the repeated lookup of the .message elements in the DOM that will slow things down. So, in case you want to call hasClass() first, it's better not to repeat the element lookup: