SO - 18449021
by Arun P Johny
HTML
<div class="wrap">
<a id="link1" href="#">link1</a>
<div class="drop" id="drop1">drop1</div>
</div> <br>
<div class="wrap">
<a id="link2" href="#">link2</a>
<div class="drop" id="drop2">drop2</div>
</div> <br><br>
jsOpenedWnd : [<div id="info"></div>]
CSS
.wrap { position: relative; }
.drop {
position: absolute;
display : none;
}
#info { display: inline; }
.wrap, .drop {
border:1px solid black;
max-width:70px;
}
html { border:1px solid black; }
JavaScript
$(document).ready(function() {
var jsOpenedWnd = "";
$.fn.toggleWnd = function() {
console.log('toggleWnd', this, jsOpenedWnd, this.is(jsOpenedWnd))
if ( !this.is(jsOpenedWnd)) {
$(this).toggle();
$(jsOpenedWnd).toggle();
jsOpenedWnd = this;
}
else {
$(this).toggle();
jsOpenedWnd = "";
}
$("#nfo").text(jsOpenedWnd);
}
$("#link1").click(function(){
$("#drop1").toggleWnd();
});
$("#link2").click(function(){
$("#drop2").toggleWnd();
});
$("html").click(function(){
$(jsOpenedWnd).toggleWnd();
});
});