Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$(document).keydown not working

Tags:

jquery

Edit::

Thanks Everyone for being helpful, but I tracked my problem as <script src="jquery.js" /> instead of <script src="jquery.js"></script>. Please vote to close

Any idea why

$(function(){
   $(document).keydown(function(evt) {
         alert('Hello');
     }); 
})

is not working? I am using Firefox 3.6.13 on Ubuntu 10.10. Well I copied it form here.

like image 367
Santosh Linkha Avatar asked Feb 24 '11 08:02

Santosh Linkha


2 Answers

Use delegate():

$(window).delegate('*', 'keypress', function (evt){
        alert("erm");
      });
like image 136
Barrie Reader Avatar answered Oct 28 '22 19:10

Barrie Reader


Use

  jQuery(document).bind('keydown', function (evt){
    alert('Hello');
  });

You may test if quick using firebug console (run it). You now get an alert box everytime you push a button on the document. I used Firefox 3.6.13 to verify this.

like image 35
Thariama Avatar answered Oct 28 '22 19:10

Thariama