I have a page with multiple text inputs, and I want to determine which of the text inputs that the user is typing into. All of the text inputs are displayed with the same code. One big constraint is that I cannot modify the actual HTML code, so I cannot add IDs or classes to the input.
Here is what the HTML looks like:
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
Here is the code that I am using to detect a keypress:
$(document).keypress(function(e) {
console.log(e.target) // will be the same for each input
});
Is there a way to distinguish between the different inputs. Is there an underlying DOM property that differentiates the text inputs such that I can access the inputs in constant time in the future(ie, does the DOM assign each input a unique id)?