Wednesday, 15 April 2015

javascript - jQuery(document).on ('focus')? -



javascript - jQuery(document).on ('focus')? -

whenever user focuses on clicks on input, want trigger method. have next code:

jquery(document).on('focus click', function(e){ console.log("focused on " + $(e.target).attr('id')); });

but whenever focus on element gives focused on undefined. what's wrong code?

you missed input selector in bind event using on().

jquery(document).on('focus click', 'input', function(e){ console.log("focused on " + $(e.target).attr('id')); });

syntax of on() .on( events [, selector ] [, info ], handler(eventobject) ), reference

javascript jquery javascript-events

No comments:

Post a Comment