Select an element by attribute in Javascript without Jquery

2

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

I wanted to do a function to skip fields in an automatic form ... I wanted to do type like this, get the tabindex of the current element and make the tabindex + 1 element gain focus ().

Follow the script to skip fields when filled in with the help of Sergio:

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 in keypress / down / up

    
asked by anonymous 06.02.2016 / 15:26

1 answer

3

You can use querySelector for selectors .

For example var tres = document.querySelector('[tabindex="3"]');

Example: link

    
06.02.2016 / 15:55