Close container with a key event
<p>i have a lot of containers in my page, the user want to be able to close then using the ESC key.</p>

<p>is there any dynamic way to identify what containers its first ( like, highest z-index ), in case that i have more then one opened? </p>

<p>the way i'm doing this its very funny/ugly.</p>

<p>i'm reinvented the wheel, i think .</p>

<p>my js:</p>

<pre><code>$(document).bind('keydown', function(e) { 
    if (e.which == 27) {

        if($("#container1").css("display") == "block"){
                // this is a sub-container inside the container1
                if($("#subContainer1").css("display") == "block"){
                    $("#subContainer1").fadeOut();
                }else{
                    $("#container1").stop(true,true).fadeOut('fast');
                }

        }else if($("#container2").css("display") == "block"){
               // this is a sub-container inside the container2
                if($('#subContainer2').css("display") == "block"){
                    $("#subContainer2").fadeOut();
                }else{
                    $("#container2").stop(true,true).fadeOut('fast');
                }
        }
    }
}); 
</code></pre>

<p>have any other intelligent way to do this ?</p>

<p>thanks!</p>
