Javascript (vanilla) - How to specify the type of an element when using querySelectorAll? -


how can specify type of element when using queryselecterall()? example, want select input fields type=text in form. not styling functionality.

this have right now:

var inputgroup = document.getelementbyid('contactform');  var inputs = inputgroup.queryselectorall("input");  (var = 0; < inputs.length; i++) {   inputs[i].addeventlistener("blur", checkinput); }  function checkinput() {   this.value === "" ? this.classname = "error" : this.classname = "valid"; } 

right targeting inputs type set submit, radio etc. want target input elements type set text.

you can use attribute selector syntax directly in call queryselectorall:

var inputs = inputgroup.queryselectorall('input[type="text"]'); 

this may miss <input> tags don't have type attribute specified @ all. can work around picking <input> tags without in selector:

var inputs = inputgroup.queryselectorall('input[type="text"],input:not([type])'); 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -