0

I need to know, how can I perform keydown on specified element or document. Now I need to perform 'click on right arrow'. I tried this: $('#page').trigger({type: 'keydown', name: 'right'});

But this doesn't work. Is here any solution, how can I perform action like this?

debute
  • 2,638
  • 6
  • 30
  • 55

3 Answers3

3

You need to pass custom event with key code for this:

var customEvent = jQuery.Event( 'keydown' );
customEvent.which = 39;
$( '#page' ).trigger( customEvent );
antyrat
  • 26,950
  • 9
  • 73
  • 75
0

Try this:

$('#element').bind('keypress', function(e) {
    if(e.keyCode==39){
        //do anything here...
    }
});
Shaeldon
  • 873
  • 4
  • 18
  • 28
0

Use jQuery Keydown function. More detail here.

$( '#page').keydown(function() {
  alert( "Handler for .keydown() called." );
});
dipak_pusti
  • 1,538
  • 2
  • 21
  • 41