javascript - Close a customized box at ESC keypress with JQuery -



javascript - Close a customized box at ESC keypress with JQuery -

i have next html code 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 if input focused otherwise not.

i want close modal-dialog box when pressed esc.

is error in js code ?

thank you

how this:

$("html").live("keyup", function(e) { if(e.keycode === 27 && !($('#modal-dialog').hasclass("no-display"))) escape_check(); } } function escape_check() { $("#modal-dialog").removeclass("no-display"); $("#feedback-modal-dialog input").each(function() { $('#modal-dialog').attr("value",""); }); $("#feedback-modal-dialog textarea").each(function() { $('#modal-dialog').val(""); }); $("#modal-dialog").addclass("no-display"); //or .hide() }

javascript jquery

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -