Activity Forums Salesforce® Discussions How to hide a div when click outside of the div?

  • Prafull

    Member
    April 14, 2016 at 8:45 am

    You can achieve this by below code :-

    $( "body").not("#toHide").click(function(){
    $("#toHide").hide();
    });

  • jitesh

    Member
    April 14, 2016 at 8:59 am

    Hi Prafull ,

    thanks for the help but this is not allowing me to open up the div when I click on the button to show the div.

  • Piyush

    Member
    April 27, 2016 at 12:18 pm

    Hello Jitesh,

    As your target has id=toHide , so you can try to achieve your requirement :

    $(document).click(function(e) {
    if (e.target.id != 'toHide' && !$('#toHide').find(e.target).length) {
    $("#toHide").hide();
    }
    });

  • shalini

    Member
    April 27, 2016 at 1:35 pm

    $('body').click(function(){
    $('div').hide();
    });

  • Prafull

    Member
    April 28, 2016 at 6:11 am

    You can use this :-

    $( “body”).not(“#toHide”).not(“#YourButtonId”).click(function(){
    $(“#toHide”).hide();
    });

Log In to reply.

Popular Salesforce Blogs