Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript JQuery: Hide a div if anything except the div and its content is clicked Reply To: JQuery: Hide a div if anything except the div and its content is clicked

#201295
gozonjoedaimar
Participant

I found this useful…

jQuery(document).click(function(event){
    // Check if clicked outside .target-div
    if (!(jQuery(event.target).closest(".target-div").length)) {
        // Hide .target-div
        jQuery(".target-div").hide();
    }
});