Keypress Event - Javascript/Jquery - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:keypress

Description

Keypress Event - Javascript/Jquery

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
   </head> 
   <body> 
      <h1 align="center"></h1> 
      <script>
 var time=10;//from  w w w  . j a  v a  2s . com
 var timer;
    $('body').keypress(function() {
        timer=setInterval(function(){
            if(time<=0)
                clearInterval(timer);
            $('h1').html(time);
            time--;
        },1000)
        $(this).unbind('keypress');
    });

      </script>  
   </body>
</html>

Related Tutorials