I am trying to implement a bit of code that Twitter use to toggle off the drop-down login box when a user clicks outside the scope of the drop-down box itself.
I am having a bit of trouble, currently if I click outside the scope of the element it works as expected but the same thing also happens when I click inside the element scope I.e. within the #form element.
HTML Markup:
<body>
<div id="form">
<div id="form-tab"></div>
<div id="form-header">FooBar</div>
<form>
<label>Test</label>
<input type="text">
</form>
</div>
</body>
jQuery Code:
$(document).mouseup(function(e) {
if ($(e.target).parent("div#form").length==0) {
hide();
}
});
function hide() {
$element.animate({
right: $rightPos
}, 1000);
}
If anyone can help me figure out where I am going wrong it would be greatly appreciated.
Thanks in advance.