In my html code I have 20 input (<input type='text'>
)elements. I want to get the index of the element I focused; Hence, before the end of <body>
, in <script>
, I wrote:
var inputs = document.getElementsByTagName('input');
function getIndex(el){
console.log(inputs.indexOf(el));
}
and added the following in every input element in html:
<input type='text' onfocus='getIndex(this)'>
but the console says:
Uncaught TypeError: inputs.indexOf is not a function
What am I doing wrong here?