'Queryselectall for selecting invalid input types
For simplicity sake, I have the following html that I didn't write and I have no control over.
<input type="text" id="532523" name="safgafg">
<input type="text" id="453462" name="sdhfd">
<input type="text num" id="2354614" name="fghjsfga">
<textarea></textarea>
I am trying to write a script for our clerk that has to enter data into this web interface, so she can copy and paste data from excel over to the web interface.
Originally, all of the inputs have always been "text" so I have been able to use the following:
document.querySelectorAll('input[type=text]').entries()
But I'm having trouble with how I can use queryselectall to get the "text num" and also a textarea. I tried to look it up on mdn but it didn't have any advice on using logical operators, and I tried this question on using logical operators but the following didn't have any effect:
document.querySelectorAll('input[type=text], input[type=text num], textarea').entries();
Solution 1:[1]
Put quotes around the value of the type
attribute in your selector.
Note: "text num" is not a valid value for the type attribute of an input. The original selector without the quotes did not work because the value contains a space.
console.log([...document.querySelectorAll('input[type="text"], input[type="text num"], textarea')]);
<input type="text" id="532523" name="safgafg">
<input type="text" id="453462" name="sdhfd">
<input type="text num" id="2354614" name="fghjsfga">
<textarea></textarea>
<div></div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |