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?

Patrik Krehák
  • 2,595
  • 8
  • 32
  • 62

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
  • 27,479
  • 9
  • 75
  • 76
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,645
  • 2
  • 23
  • 42