JSFiddle - React, Tailwind, and code Playground

HTML

<input tabindex="3" type="text" id="cnumber1" class="inputBx ccNumber" style="width:57px;margin-left: 11px!important" maxlength="1" size="1" autocomplete="off" />
        <input tabindex="4" type="text" id="cnumber2" class="ccNumber" style="width:57px;"  maxlength="1" size="1" autocomplete="off"/>
        <input tabindex="5" type="text" id="cnumber3" class="ccNumber" style="width:56px;"  maxlength="1" size="1" autocomplete="off"/>
        <input tabindex="6" type="text" id="cnumber4" class="ccNumber" style="width:56px;"  maxlength="1" size="1" autocomplete="off"/>

JavaScript

(function($) {
  $.switchFocus = function($this) {
    $this.unbind('keyup');
    $this.each(function() {
      $(this).keyup(function(){
        var $this = $(this),
        inputVal = $this.val(),
        iLen = inputVal.length,
        $nextEle = $this.next();
        if (iLen == $this.attr("size") && $nextEle.length > 0){
          if($nextEle.val().length === 0)
            $nextEle.focus();
            setTimeout(function(){$nextEle.focus()},0);
        }
      });
    });
  }
}(jQuery));
    
    $(function() {
      $.switchFocus($("input"))
    });