When the element is clicked, I want to add a class to the body element, but with a slight delay. Thus, element1 is clicked, and then after 0.5 seconds the body is the specified new class.
I used this, which works to the extent ...
$('.element1').click(function() { $('body').delay(500).queue(function(){ $(this).addClass('left-bg') }); });
However, I have another click event that removes this left-bg class from the body.
$('.another-element').click(function() { $('body').removeClass('left-bg'); });
But then the next time you click the .element1 element, it will not apply the left-bg class to the body at all.
Hope this makes sense. Can someone help me with this or suggest another way to do this?
jquery delay
user2586455
source share