focus first input on enter last input javascript code example
Example 1: On pressing enter change the focus to the next input field
public focusNext(e) {
console.log('here');
try {
for (let i = 0; i < this.inputsArraY.length; i++) {
if (e.code === 'Enter' && e.target.id === this.inputsArraY[i]) {
document.querySelector(`#${this.inputsArraY[i+1]}`)//.focus()
}
}
} catch (error) {
console.log(error);
}
}
Example 2: jquery give control focus
$('.class').focus();
$('#name').focus();