Home arrow JavaScript arrow Page 2 - 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 - Review: mouse overs and keydown events with jQuery
(Page 2 of 4 )

In case you haven't had the chance to read the previous tutorial of the series, where I explained how to handle mouse overs and keydown events with the jQuery library, below I listed a couple of examples that show how to perform these specific tasks. Here they are:

(example on handling a 'mouseover' event with jQuery)


<!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 mouseover 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").mouseover(function(){

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

});

});

</script>

</head>

<body>

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

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

</body>

</html>



(example on handling a 'keydown' event with jQuery)


<!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 keydown 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").keydown(function(){

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

});

});

</script>

</head>

<body>

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

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

</body>

</html>

 

These were really simple to code and grasp, right? As you can see, the pair of examples listed above demonstrate in a nutshell how to build basic JavaScript applications that respond to mouse overs and keydown events. Of course, in this case, the applications will display a couple of alert boxes on screen in response to those events. This simple concept, however, can be easily applied when working with real-world projects.

So far, so good. At this point, you hopefully realized that handling mouse and keyboard events by way of the jQuery library is simple. So, what comes next? Well, as I mentioned in the introduction, in the section to come I'm going to provide you with another hands-on example to demonstrate how to process keypress events by using a brand new method of the jQuery package.

To see how this will be achieved, please click on the link that appears below and keep reading.


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 10 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials