JSFiddle - React, Tailwind, and code Playground
HTML
<form>
<input type="text" name="txt">
<button name="btn">Check the text</button>
</form>
JavaScript
var $btn = $('[name="btn"]'),
$txt = $('[name="txt"]');
$('form').on('click', $btn, function(e) {
e.preventDefault();
console.log($(':focus').length);
if($txt.is(':focus')) {
console.log('Input is focused. Handle the click');
} else {
console.log('Input is not focused');
}
});
$txt.on('keydown', function() {
console.log($(':focus').length);
});