Skip to content

Instantly share code, notes, and snippets.

@Marlysson
Last active April 9, 2017 00:51
Show Gist options
  • Select an option

  • Save Marlysson/ca2e33e9da7f2ac2922e77f74fb257e7 to your computer and use it in GitHub Desktop.

Select an option

Save Marlysson/ca2e33e9da7f2ac2922e77f74fb257e7 to your computer and use it in GitHub Desktop.
Focar próximo elemento do html ao pressionar ENTER em um input
<input type="" name="" placeholder="Input 1">
<input type="" name="" placeholder="Input 2">
<input type="" name="" placeholder="Input 3">
<button>Botão 3</button>
<script type="text/javascript">
let botoes = document.querySelectorAll("input");
botoes.forEach(function(elemento,indice){
elemento.addEventListener("keydown",function(evento){
if (evento.keyCode == 13){
proximo = this.nextElementSibling;
proximo.focus();
}
});
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment