I have the following HTML code for dialog box:
<div id="modal-dialog" class="no-display">
<div class="form">
<div class="close">
</div>
<div align="center">
<h2><u>form</u></h2>
</div>
<form>
<label for="yourname">Full name:</label><input type="text" name="yourname">
<label for="email">E-mail:</label><input type="text" name="email">
<label for="message">Message:</label></textarea><textarea type="text" name="message"></textarea><br/>
<div class="clear"></div>
<p align="center"><button>Send feedback</button></p>
</form>
</div>
</div>
The javascript :
$("#clickfeed").live("click", function() {
$("#modal-dialog").removeClass("no-display");
});
I wrote:
$("#modal-dialog").live("keyup", function(e) {
if(e.keyCode === 27 && !($(this).hasClass("no-display")))
{
$("#feedback-modal-dialog input").each(function() {
$(this).attr("value","");
});
$("#feedback-modal-dialog textarea").each(function() {
$(this).val("");
});
$("#modal-dialog").addClass("no-display"); //or .hide()
}
});
The ESC key works only if an input is focused otherwise not.
I want to close modal-dialog box when pressed ESC.
Is a mistake in my JS code ?
Thank you
How about this: