Select an element per attribute in Javascript without Jquery

Asked

Viewed 1,954 times

3

How to select an element by some type attribute (type, for, value) as in jQuery ex: [type=text]?

I wanted to make a function to jump fields in an automatic form...I wanted to do like this, take the tabindex of the current element and make the element tabindex + 1 wins Focus().

Follow the script to skip fields when they are completed with the help of Sérgio:

function pulacampo(id){
	var campo = document.getElementById(id);
	var proximo = campo.tabIndex +  1; 
	var proximoElemento = document.querySelector("[tabindex='" + proximo + "']");
			
			if (campo.value.length == campo.maxLength){
				proximoElemento.focus();	
			
			
		}
	
}

You just need to set the tabindex of the fields and insert the function into the keypress/down/up

  • 1

    It’s like jQeury but using the querySelector. Forehead document.querySelector('[type="text"]');

1 answer

4


  • Thank you, it worked perfectly, I’ll leave the function to whoever needs it

Browser other questions tagged

You are not signed in. Login or sign up in order to post.