2

I understand that calling jQuery events $(selector).blur(); will call trigger and run the blur event handler(s).

Does this give any other element on the page e.g. document, body, focus?

N.B. While this seems fairly simple I have not found details on the jQuery API or SO or Google.

StuperUser
  • 9,939
  • 10
  • 70
  • 127

1 Answers1

1

I don't think it gives any other element focus. It seems to just take focus away completely (actually, not in IE see my edit). I wired up a jsfiddle example along these lines:

HTML

<div id="test">
    <input id="test2" />
    <input id="test3" />
    <input id="test4" />
</div>

JavaScript

$(function() {
    $('*').focus(function() {
        alert(this.id);
    });
    $('input').keypress(function(evt) {
        if (evt.which == '13') {
            $(this).blur();
            evt.preventDefault();
        }
    });
});

Basically, it alerts when any element receives focus and when you press enter in any of the input boxes, it calls .blur(). In Opera no other element gets focus when this happens. In Firefox the alert box takes focus away from the element so you need to use console.log() instead of alert() but it acts the same way otherwise.

Edit
I checked it in IE and it seems that focus is changed to the body element. If you have it alert(this); instead of alert(this.id); it says that the body element gets focus when the inputs lose it.