JSFiddle - React, Tailwind, and code Playground
HTML
<textarea style="width:100%">function should fire when the next input is tabbed into or clicked (focused), but not when changing browser tabs</textarea>
<input>
JavaScript
var times = 0;
var prevActiveElement;
$( window ).on( "blur", function(e){
prevActiveElement = document.activeElement;
});
$('input').on('focus', function() {
if (document.activeElement === prevActiveElement) {
return;
}
prevActiveElement = document.activeElement;
times++;
$(this).after('<br>Focused ' + times + ' times');
}).on( "blur", function(){
prevActiveElement = null;
});