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.
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">
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.