Источник :
https://api.jquery.com/mouseout/
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>mouseout demo</title>
<style>
div.out {
width: 40%;
height: 120px;
margin: 0 15px;
background-color: #d6edfc;
float: left;
}
div.in {
width: 60%;
height: 60%;
background-color: #fc0;
margin: 10px auto;
}
p {
line-height: 1em;
margin: 0;
padding: 0;
}
</style>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
<div class="out overout">
<p>move your mouse</p>
<div class="in overout"><p>move your mouse</p><p>0</p></div>
<p>0</p>
</div>
<div class="out enterleave">
<p>move your mouse</p>
<div class="in enterleave"><p>move your mouse</p><p>0</p></div>
<p>0</p>
</div>
<script>
var i = 0;
$( "div.overout" )
.mouseout(function() {
$( "p", this ).first().text( "mouse out" );
$( "p", this ).last().text( ++i );
})
.mouseover(function() {
$( "p", this ).first().text( "mouse over" );
});
var n = 0;
$( "div.enterleave" )
.on( "mouseenter", function() {
$( "p", this ).first().text( "mouse enter" );
})
.on( "mouseleave", function() {
$( "p", this ).first().text( "mouse leave" );
$( "p", this ).last().text( ++n );
});
</script>
при клике тоже самое
<script>
$( "любой блок вне" ).click(function() {
$( ваш блок который скрыть ).hide();
});
</script>