Andrew Novikov
Andrew Novikov

Reputation: 109

ReferenceError: event is not defined on keyup event in firefox

Why this code not work in Firefox? I want to make the switch pictures in gallery on keyup event. I had read similar problems and answers, but no one help me. jQuery 1.4.4 My code:

  $('body').live('keyup',function(e){

    if(e.keyCode  == 37) {
      $('.daPrev').click()
    }

    else if(e.keyCode  == 39) {
      $('.daNext').click()
    }

  })

When i press, in console:

ReferenceError: event is not defined

Upvotes: 0

Views: 1092

Answers (3)

Andrew Novikov
Andrew Novikov

Reputation: 109

Problem has been solved using jQuery migrate. Thank's you all

Upvotes: 0

Xandrios93
Xandrios93

Reputation: 2315

your code does not seem to caus the reference error. check other functions triggered, when you press.

i made a fiddle, tried in FF and console will log "37"

fiddle

$('body').live('keyup',function(e){

  console.log('37')
    if(e.keyCode  == 37) {
      $('.daPrev').click()
    }

    else if(e.keyCode  == 39) {
       $('.daNext').click()
    }

})

Upvotes: 0

TwoPointThrowaway
TwoPointThrowaway

Reputation: 31

I don't see any variable called event in your code, and it looks valid. However, some things you can try:

  • Use .delegate
  • Try a newer version of jQuery and switch to .on

.delegate:

$.delegate(selector, eventType, handler);

I.e.

$.delegate("div", "keyup", function(e) {...});

Upvotes: 1

Related Questions