Home arrow JavaScript arrow Page 2 - Introducing the jQuery JavaScript Library
JAVASCRIPT

Introducing the jQuery JavaScript Library


Welcome to the first part of a seven-part series on the jQuery JavaScript library. In this article I will provide you with a quick overview of how to use the library, including its helpful $() function and the ready() method. The jQuery library allows you to build unobtrusive client-side applications with only minor effort, and its syntax is simple to grasp.

Author Info:
By: Alejandro Gervasio
Rating: 4 stars4 stars4 stars4 stars4 stars / 4
August 12, 2009
TABLE OF CONTENTS:
  1. · Introducing the jQuery JavaScript Library
  2. · Getting started using jQuery
  3. · More examples of the $() function and the click() method
  4. · Firing up a function with a mousedown event

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Introducing the jQuery JavaScript Library - Getting started using jQuery
(Page 2 of 4 )

Now that you've read the introduction, I'm sure that you're curious about how to get started using the "jQuery" library in a useful way. Let me show you an introductory example that hopefully will satisfy your curiosity.

In this case, I'm going to use the library in question to display a simple alert box on screen, before redirecting users to Dev Shed's front page. Here's how this initial 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</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").click(function(){

alert('You are going to visit Devshed.com now...');

});

});

</script>

</head>

<body>

<h1>Basic example on using jQuery</h1>

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

</body>

</html>

 

Regardless of the group of additional CSS styles that I included in the previous example, you should pay attention specifically to the way that the "jQuery" package does its thing. As you can see, first the library's source file is downloaded separately, which you've done probably hundreds of times before.

Then, and here is where things get really interesting, I used a brand new method, called "ready()," to assign an "onclick" event handler to a basic link after the complete web document finishes loading, thus displaying an alert box each time a user clicks on it.

Logically, there are a couple of details that you should grasp quickly with regard to this particular example. First, you'll note the use of a $() function (this one is indeed very similar to Prototype's version) to navigate the web page's DOM very easily, and second, the utilization of a "click" method to display the aforementioned alert box.

Okay, now that you hopefully understood how the previous hands-on example works, I think that you'll agree with me that the "jQuery" library is quite easy to use and its programming interface is also intuitive, right? Nonetheless, this is only the first example of a long list, so in the next section I'm going to teach you how to use the library, this time to display a prompt box before users leave a web page.

To learn the full details on how this will be done, 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