JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JSFIDDLE</title>
</head>
<body>
<fieldset id ="test">
<input type="text" id="1" maxlength="5" size="5"/>
<input type="text" id="2" maxlength="5" size="5"/>
<input type="text" id="3" maxlength="5" size="5"/>
<input type="text" id="4" maxlength="5" size="5"/>
<input type="text" id="5" maxlength="5" size="5"/>
</fieldset>
</body>
</html>
JavaScript
$(document).ready(function() {
$("#test input[type=text]").keydown(function(e){
var $this = $(this),
val = $this.val(),
$prev,
$parent;
if(e.which == 8){
if(val.length == 0){
$prev = $this.prev();
$prev.focus().val($prev.val());
}
}
else if(val.length == $this.attr('maxlength') ){
$parent = $this.parent();
if($parent.children().last().attr('id') == $this.attr("id")){
$parent.next().find(':input').focus();
}else{
$this.next("input").focus();
}
}
});
});