user674905
user674905

Reputation: 19

Help with focus in jquery

I have two button on my confirmation popup (popup_ok & popup_cancel), I want to restrict focus on either of the two buttons untill user decides what he/she wants to do. Uptill now im doing the following

$("#popup_cancel").blur(function() {

    $("#popup_ok").focus();
    $("#popup_ok").focus();

});

but this is not working, kindly guide me to better approach

Thanks in advance.

Upvotes: 1

Views: 149

Answers (1)

Prutswonder
Prutswonder

Reputation: 10064

I assume it's not practical to perform a focus() inside a blur() event, but if you insist, I advice you to use a small timeout to force the focus to execute outside of the event bubble:

setTimeout(function() { $("#popup_ok").focus(); }, 10)

(Updated based on Matt's comment to prevent using eval())

Upvotes: 1

Related Questions