Onblur, what is the next control that will focus?

I am running some onblur () code of a text field. But I want to do something different if the user clicked the cancel button to call onblur (). Is there a way in the onblur () event handler function to find out that the control is going to receive focus and respond accordingly?

Joseph

+3
source share
2 answers

Yes, you can get the target as follows:

var target = event.explicitOriginalTarget || document.activeElement;

(I think I found this on StackOverflow somewhere).

+5
source

, , -, focus - , .

- ( ):

var focusedElem = null;
var focusedTime = 0;

$("input", "#myForm").focus(function() {
    focusedElem = this;
    focusedTime = new Date();
})
.blur(function() {
    setTimeout(function() { //set a small timeout to wait for the other control to receive focus and set itself as focusedElem
        if (focusedElem && (new Date() - focusedTime) < 15) {
            //do Something with focusedElem;
        }
    }, 10);
});
+1

Source: https://habr.com/ru/post/1730628/


All Articles