toggleclass

addClass and removeClass in jQuery - not removing class

扶醉桌前 提交于 2019-11-27 19:21:06
I'm trying to do something very simple. Basically I have a clickable div 'hot spot', when you click that it fills the screen and displays some content. I achieved this by simply changing the class of div, removing 'spot' and adding 'grown' and there's a little CSS animation to make it grow. This works fine. The problem is, within this div there is a close_button, which at the moment is just text. I want this to switch the classes back - i.e. remove grown and readd spot. It doesn't do this when clicked. I believe it's to do with the element not having those classes when the DOM loads, but I'm

addClass and removeClass in jQuery - not removing class

拥有回忆 提交于 2019-11-27 04:22:26
问题 I'm trying to do something very simple. Basically I have a clickable div 'hot spot', when you click that it fills the screen and displays some content. I achieved this by simply changing the class of div, removing 'spot' and adding 'grown' and there's a little CSS animation to make it grow. This works fine. The problem is, within this div there is a close_button, which at the moment is just text. I want this to switch the classes back - i.e. remove grown and readd spot. It doesn't do this

Easiest way to toggle 2 classes in jQuery

空扰寡人 提交于 2019-11-26 03:47:29
问题 If I have class .A and class .B and want to switch in between on button click, what\'s a nice solution for that in jQuery? I still don\'t understand how toggleClass() works. Is there an inline solution to put it in onclick=\"\" event? 回答1: If your element exposes class A from the start, you can write: $(element).toggleClass("A B"); This will remove class A and add class B . If you do that again, it will remove class B and reinstate class A . If you want to match the elements that expose