Reputation: 12747
Whenever the user focuses on clicks on an input, I want to trigger a method. I have the following code:
jQuery(document).on('focus click', function(e){
console.log("focused on " + $(e.target).attr('id'));
});
But whenever I focus on an element it just gives focused on undefined
. What's wrong with this code?
Upvotes: 6
Views: 44729
Reputation: 9370
Try:
$(document).on('focus click', 'input', function(e){
console.log("focused on " + e.target.id);
});
Also just e.target.id
is enough..
Upvotes: 7