I'm trying to 'listen' to clicks on any input field using the snippet below
document.getElementsByTagName('input').onclick = function(){
console.log('clicked an input field');
}
But nothing happens when I click on the input fields.
I double checked to make sure that input fields are being detected with getElementsByTagName using this snippet and it shows 200 objects
elems = document.getElementsByTagName('input');
console.dir(elems);
Screenshot from console:
Is there a reason why this would not work? I tried moving code to different sections to make sure that document is loaded when it runs.
Plain javascript, not using jquery