obtener todos los elementos de tipo input text in javascript

To obtain all the input elements of type text using JavaScript, you can use the getElementsByName() method or the querySelectorAll() method.

Using getElementsByName():

index.tsx
var inputs = document.getElementsByName('input');
var textInputs = [];

for (var i = 0; i < inputs.length; i++) {
  if (inputs[i].type === 'text') {
    textInputs.push(inputs[i]);
  }
}

console.log(textInputs);
213 chars
11 lines

Using querySelectorAll():

index.tsx
var textInputs = document.querySelectorAll('input[type="text"]');

console.log(textInputs);
92 chars
4 lines

Both of these methods will return a list of input elements of type text. You can then modify or access their properties or values as needed.

related categories

gistlibby LogSnag