When I click outside of the expanded div, I want it to close.
This is the HTML code I have:
<div id="panel">
<div>
<h1>Welcome to jquery demo</h1>
<h3>Welcome to jquery demo</h3>
<h3>Welcome to jquery demo</h3>
<h3>Welcome to jquery demo</h3>
<h3>Welcome to jquery demo</h3>
</div>
</div>
<div class="tab">
<ul class="loginleft">
<button class="sc-button g-opacity-transition sc-button-large loginButton" tabindex="0">Log in</button>
</ul>
<ul class="login">
<li class="left"> </li>
<li>Hello Guest!</li>
<li class="sep">|</li>
<li id="toggle">
<a id="open" class="open" href="#">More Info</a>
<a id="close" style="display: none;" class="close" href="#">Close Panel</a>
</li>
<li class="right"> </li>
</ul>
</div>
This is the JS code:
$(document).ready(function() {
// Expand Panel
$("#open").click(function(){
$("div#panel").slideDown("slow");
});
// Collapse Panel
$("#close").click(function(){
$("div#panel").slideUp("slow");
});
// Switch buttons from "Log In | Register" to "Close Panel" on click
$("#toggle a").click(function () {
$("#toggle a").toggle();
});
});
How can I also close the expanded div when clicked outside the area?