I have a hidden div which opens up on click of a link text. I need to hide the div and remove the active
class from the link text when user clicks outside the div
anywhere on the body.
I have used body onclick
to hide the div but it is hiding the div on div click as well. I don't want to close the div only on body click, not on the div click. How can I stop the action on div click?
here is what I have tried
$('.link').click(function(e){
e.stopPropagation();
$(this).toggleClass('active');
$(".box").slideToggle();
});
$('body').click(function(e) {
$(".box").hide();
$(".link").removeClass('active');
});