1

I used this answer to disable arrow and pgdown and pgup keys actions (scrolling). but I need to set actions of this keys to default (scrolling) after event.preventDefault() called in my jquery code.

How can I do this.

Community
  • 1
  • 1
SirSaleh
  • 1,192
  • 3
  • 21
  • 35

2 Answers2

2

Hard to answer without better specifics, but if I understand what you have properly if you have something you can track state with you can preventDefault when you wish to block this behavior and let it fall through otherwise:

Psudocode:

var state = {
   blockArrows: true;
}

$('#my_widget').keydown(function(e) {
  if(state.blockArrows) {
    e.preventDefault();
  }
  // ...else allow the event to do its normal thing....///
});
1

To reverse preventDefault(), you need to unbind the original action and then re-call it.

$(document).keydown(function(e) {
    e.preventDefault()
    // Do stuff until you need to recall the default action
    $(this).unbind('keydown').keydown()
})

How to unbind a listener that is calling event.preventDefault() (using jQuery)?

Community
  • 1
  • 1
Nate Weller
  • 366
  • 3
  • 5