Hide div when clicking outside
- by scferg
I've searched and search not only google but also here and still have to find a solution that will work.
I have a div that is hidden by default, then toggled by clicking on a link. I also want it to hide when you click outside of the div. Simple, I thought, but nothing I've tried had worked yet.
This is the jquery:
<script type="text/javascript">
function toggleDiv(divID) {
$("#"+divID).fadeToggle(200);
}
</script>
And the link that toggles it:
<a onclick="toggleDiv('myDiv');">Link</a>
And then the div:
<div id="myDiv">
stuff
</div>
If anyone has any advice, I would really appreciate it.