Home arrow JavaScript arrow Page 3 - More Mouse and Keyboard Events with the jQuery JavaScript Library
JAVASCRIPT

More Mouse and Keyboard Events with the jQuery JavaScript Library


Welcome to the fourth article in an eight-part series on the jQuery JavaScript library. In this part, I will walk you through using a pair of brand new methods provided by the library for processing some additional keyboard-related actions, such as keydown and keyup events.

Author Info:
By: Alejandro Gervasio
Rating: 3 stars3 stars3 stars3 stars3 stars / 2
September 02, 2009
TABLE OF CONTENTS:
  1. · More Mouse and Keyboard Events with the jQuery JavaScript Library
  2. · Review: mouse overs and keydown events with jQuery
  3. · Manipulating a keypress event with the keypress() method
  4. · Using the keyup() method

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
More Mouse and Keyboard Events with the jQuery JavaScript Library - Manipulating a keypress event with the keypress() method
(Page 3 of 4 )

In the previous section, you hopefully grasped the logic that stands behind handling mouse overs and keydown events with the jQuery JavaScript library. As you learned before, assigning these concrete event handlers to an element within a web document is only a matter of tying the proper method to the element in question. It's that simple, really.

Since jQuery provides a concrete method for handling each JavaScript event, you won't be surprise if I tell you that it can be used to process keypress actions in a simple and intuitive manner by using an approach nearly identical to the ones shown in previous examples.

Below I included a code sample which demonstrates how to create a simple JavaScript application that responds to a keypress event. Here's how this brand new example looks:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Basic example on using jQuery with keypress event</title>

<style type="text/css">

body{

padding: 0;

margin: 0;

background: #fff;

}

h1{

font: 24px bold Arial, Helvetica, sans-serif;

color:#000;

}

</style>

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

$(document).ready(function(){

$("a").keypress(function(){

alert('Redirecting to Devshed.com now!');

});

});

</script>

</head>

<body>

<h1>Basic example on using jQuery with keypress event</h1>

<a href="http://www.devshed.com/">Visit Devshed.com now!</a>

</body>

</html>

Well, as you can see in the above example, I used a brand new method, called "keypress()," to intercept the homonymous event. In this case, as I did with other previous hands-on examples, the response to the event is simply displaying an alert box, but naturally the same logic can be implemented when developing real-world web applications.

Okay, now that you hopefully understood how to use the handy "keypress()" method bundled with the jQuery JavaScript library, it's time to continue exploring its capabilities for processing keyboard-related events.

Therefore, in the last section of this tutorial I'm going to teach you how to use the library to intercept "keyup" events.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials