any ideas why this not work?
$(document).ready(function ubsrt()
{
$(window).bind('keyup', function(e) { if (e.keyCode == '27')
{
$('body').append('focus window <br />');
$(window).focus();
$(document).focus();
} });
$('#test').focus();
});
I think what you’re trying to do is to remove focus from the text box when you hit escape, so try this (in your event handler):
$(e.target).blur();
In this example focus never leaves from the window so you can’t assign it back.
You could test to see if the target is valid for a blur call too – e.g. test if it’s an input.