jqueryfadefading

jquery show and hide button


I have a small issue with with jquery show and hide.

I have a buttons that activates the click and shows a box.

Is it possible to click outside of the box to fade the box out

Here is my code.

$('.normal-btn.interest').click(function(){
    $('.categories-wrap').fadeIn();
})

$('what needs to be here? ').click(function(){
    $('.categories-wrap').fadeOut();
})

Solution

  • Yes, you can bind the click event to the document like:

    $('.normal-btn.interest').click(function(e){
    
        // Prevent the event from bubbling up the DOM tree
        e.stopPropagation();
        $('.categories-wrap').fadeIn();
    });
    
    $(document).click(function(){
        $('.categories-wrap').fadeOut();
    });