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
Post a Comment