1

I have a textbox where I'm trying to focus when blur event is triggered as follows:

<input type='text' onblur="$(this).focus()"/>

This works perfectly in Chrome and IE, but fails in Mozilla.

How do I solve this?

Here's the Problem.

Anders
  • 8,307
  • 9
  • 56
  • 88
Nikunj Madhogaria
  • 2,139
  • 2
  • 23
  • 40

2 Answers2

1

Introduce a timer to make sure that your code runs in an event loop separate from the one triggering the "blur" event:

document.getElementsByTagName("input")[0].addEventListener("blur", function() {
    var element = this;
    setTimeout(function() {
        element.focus();
    }, 1);
}, true);

Forked fiddle.

Pointy
  • 405,095
  • 59
  • 585
  • 614
0

Try to use this. form,

    <form>
        Name: <input type='text' name='name'></input>
    </form>

JQuery

$(document).ready(function(){
   setupForms();
});

function setupForms(){
    $('input').focus(function(){
        $(this).css('outline-color', '#FF0000');
    });
}
Alex3005
  • 7
  • 1