Arunkumar Vasudevan
Arunkumar Vasudevan

Reputation: 5330

input forced to focus while onblur event

I have try to focus while onblur Event. it works on chrome not on firefox. how to sort out.

function a() {
    $("#login").focus();
}
$(document).ready(function() {
    $("#login").focus();
});
<input id="login" onblur="a()"></input>

Please help.

Upvotes: 1

Views: 107

Answers (3)

user4688751
user4688751

Reputation:

You can just remove the onblur function and write instead:

$(document).ready(function () {
    $("#login").focus();

    $(document).on('click', function () {
        $("#login").focus();
    });
});

Live jsfiddle: http://jsfiddle.net/ysjkzvh7/

Upvotes: 2

Subha
Subha

Reputation: 1051

If you don't want the input to lose focus, just unbind the blur function from it.

Try this -

$(document).ready(function() {
    $("#login").unbind('blur');
});

Upvotes: 1

nada
nada

Reputation: 972

Do something like that;

$( "#login" ).blur(function() {
  $(this).focus();
});

and

<input id="login"></input>

just try different things. But every browser is different.

Upvotes: 1

Related Questions