obtener el id de un input text de una lista de inputs html in javascript

To obtain the id of an input text element from a list of input elements in HTML using JavaScript, you can use the following code:

index.tsx
let inputList = document.getElementsByTagName('input'); // Get all input elements
for (let i = 0; i < inputList.length; i++) {  // Loop through each input element
  if (inputList[i].type === 'text') {  // Check if it's a text input
    let id = inputList[i].id;  // Get the id of the text input
    console.log(id);  // Print the id to the console
  }
}
354 chars
8 lines

This code first gets all the input elements using document.getElementsByTagName('input'). It then loops through each input element and checks if its type is 'text' using inputList[i].type === 'text'. If it is a text input, it gets the id of the input using inputList[i].id and prints it to the console using console.log(id).

gistlibby LogSnag