JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text" name="firstname" />
<input type="text" name="lastname" />

JavaScript

$('input[name=lastname]').focus(function() {
  if (!$('input[name=firstname]').val()) {
    alert('First enter your first name');
      var th = this;
      setTimeout(function(){
       //   $(th).blur();
          $('input[name=firstname]').focus();
      },50);
  }
});