I’m trying to use jquery to detect when the ENTER key is pressed AND I need to know which form element triggered the event. I found code for detecting when the ENTER key is pressed but I can’t determine the ID of the form element that triggered it.
$(document).keypress(function(e) {
if( e.which == 13 )
{
alert( $(this) ); //This shows an object is accessible
alert( $(this).attr("id") ); //This displays "undefined". Why? How do I determine the id of the object?
}
});
I finally figured out that $(this).attr(“id”) was never going to return an id because it was triggered by a keypress, not by the form field that had the focus prior to the keypress, which is what I was really looking for.