How to hide div when click outside using jquery

Today, We want to share with you hide div when click outside using jquery.In this post we will show you jquery hide div on click anywhere, hear for How to hide a div on clicking outsides of it with JavaScript/jQuery? we will give you demo and example for implement.In this post, we will learn about Close div if click outsides with an example.

Hide a DIV When User Clicks Outside of it using jQuery

$(document).mouseup(function (e){

	var container = $("#YOUR_TARGETED_ELEMENT_ID");

	if (! && container.has( === 0){


Example 1: index.html

<!DOCTYPE html>
         window.onload = function(){
            var hideMe = document.getElementById('hideMe');
            document.onclick = function(e){
               if( !== 'hideMe'){
         = 'none';
      <div id="hideMe">Click outside this div and hide it.</div>

Hide Div On Click Outside Using Jquery
Example 2:

    var eti = $("#element_target_id");
    if(! && eti.has( === 0){

how to hide div on click outside using jquery?

Example 3: if clicked outside of div jquery

    var container = $("YOUR CONTAINER SELECTOR");

    if (! && container.has( === 0) 

I hope you get an idea about How to use JavaScript to hide a DIV the user clicks outside of it?.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Also Read This 👉   Laravel get multiple checkbox value From View to Controller