On click out side a div close it.

nik
nik
Member
166 Points
6 Posts

Hi,

how to close a div on click out side the div?

Views: 8524
Total Answered: 1
Total Marked As Answer: 1
Posted On: 23-Apr-2015 02:19

Share:   fb twitter linkedin
Answers
Brian
Brian
Moderator
2232 Points
14 Posts
         

Hi Nik,

use following example code :

<div id="dvContainer" style="background-color:yellow;width:100%;height:300px;">
<div style="background-color:red;width:100px;height:100px;">
other div
</div>
<div class="divDoNotClose" style="background-color:green;width:100px;height:200px;position:fixed;z-index:100000;">
Do not close when click on this
</div>
</div>
<script type="text/javascript">
$("#dvContainer div").click(function (e) {
if ($(e.target).attr("class") != "divDoNotClose") {
$(".divDoNotClose").css("display", "none");
}
});
</script>

 

Posted On: 24-Apr-2015 23:58
 Log In to Chat