Reputation: 565
I have below jquery code which is execute on keypress but I would like to execute same on button click. Please help me.
$('#itemselected').live('keypress', function() {
//some code which using $(this) also.
}
Upvotes: 0
Views: 167
Reputation: 723
var myFunction = function(event){
console.debug(event);
//do your stuff here
};
$('#itemselected').on('keypress', function(event) {
myFunction(event);
}
$('#itemselected').on('click', function(event) {
myFunction(event);
}
Upvotes: 1
Reputation: 1008
I think you can just add 'click' to the list of event types like so:
$('#itemselected').on('keypress click', function() {
//some code which using $(this) also.
});
Upvotes: 0
Reputation: 32354
Try to trigger the keypress on click
$('button').click(function() {
$('#itemselected').trigger('keypress');
});
Upvotes: 0