.on( "keydown" doens't work but .on( "click" does $( ".aAU" ).on( "keydown", function() {
alert('Key pressed'); // no alert displayed when a key is pressed
});
$( ".aAU" ).on( "click", function() {
alert('clicked'); // alert displayed when a click is done
});
depends where focus is when you key down
this will only work if an input element of class aAU has focus
@Snapey Thanks for trying to help me.
So I did this:
$(function() {
$('.aAU').focus();
});
$( ".aAU:focus" ).on( "keydown", function() {
alert('Key pressed'); // no alert displayed when a key is pressed
});
But no alert is displayed when a key is pressed.
@ilex01 what type of element is it?
$(function() {
$('.aAU').focus();
});
only works if there can only be one element with that class
@ilex01 turn it into an ID '#aAU' rather than it being a class '.aAU' and make sure no other element is sharing that ID.
Please sign in or create an account to participate in this conversation.