Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On focusout, focus

Tags:

jquery

Does jQuery prevent this type of behavior?

$("input").focusout(function() {
    $(this).focus();
});
like image 669
colindunn Avatar asked Jun 20 '11 21:06

colindunn


2 Answers

This is how it's done (works cross-browser):

$('input').blur(function() {
    var that = this;
    setTimeout(function() { $(that).focus(); }, 0);
});

Live demo: http://jsfiddle.net/jzt2Z/1/

like image 166
Šime Vidas Avatar answered Oct 19 '22 23:10

Šime Vidas


1) Actually it works in Chrome. Here is an example: http://jsfiddle.net/8WP53/

Once 1st input gets focuseout - it remains focused, and user cannot focus any other input

2) in IE I get an error "Stack overflow" (brand name StackOverflow.com error :) )

3) Strange, but in Firefox you can select any input, but no error is being produced

like image 28
Scherbius.com Avatar answered Oct 19 '22 23:10

Scherbius.com