Ashish Kasma
Ashish Kasma

Reputation: 3652

How to enable keydown for full document and disable keydown for one div

I am using fancybox for form popup and my client does not want to background should be scroll

Firefox is still allow user to scroll background via arrow keys.

Now I blocked the user to press arrow key till popup for complete document, but it will stop the same keydown in my form also.

is these any option for user to block event for all document except form ?

Upvotes: 0

Views: 379

Answers (2)

palaѕн
palaѕн

Reputation: 73916

To enable keydown for full document:

$(document).keydown(function(event) {
  var charCode = event.which;
  alert('Handler for .keydown() called - ' + charCode );
});

And to disable keydown for one div:

$('#target').keydown(function(event) {
  event.preventDefault()
});

where target is the ID of the specific div.

Upvotes: 1

SachinGutte
SachinGutte

Reputation: 7055

try this-

$(document).keydown(function(event){
  if ($(event.target).is('.theForm'))
      event.stopPropogation();
  else
      // block scrolling  
});

Upvotes: 4

Related Questions