0

given an application that can produce a webpage that has multiple and varying instances of the following html element:

<input type="text" class="form-control" name="jpd-model" id="jpd-model-1" value="XXXX-900L-XXXX~(120,277)">

i have the following javascript code:

const modelInputs = document.getElementsByName('jpd-model')
console.log(modelInputs)

it returns correctly a NodeList of all the elements that match correctly.

however the code below is an attempt access an item in the NodeList above:

const modelInputs = document.getElementsByName('jpd-model')
console.log(modelInputs[0])

but instead returns undefined

i would expect the first node of modelInputs

Is undefined expected here, and if not what could be causing that?

using latest brave browser on linux

this is a redo of a question i asked previously that got closed, i'm hoping i fix correctly here.

this was closed because it was assumed another question answered this, it does not, the difference here is that if that was the case then the first code example i have would not work either, but it does.

Pompey Magnus
  • 1,651
  • 4
  • 15
  • 27

0 Answers0