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 - More examples of the $() function and the click() method (Page 3 of 4 )
As you learned in the previous section, displaying an alert box when a link is clicked is actually a straightforward process thanks to the use of the $() function and the "ready()" method provided by the "jQuery" package.
However, let me go one step further and show you another practical example. It will show how to use the method to display a confirm box before redirecting users to Dev Shed's main page.
Here's the code sample that performs the aforementioned task:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
That was easy to code and read, wasn't it? In this specific case, the $() function and the pertinent "ready()" method are used in conjunction to display a trivial confirm box each time a user clicks on the link that points to "Devshed.com." As you can see, whether the visitor is taken directly to the Dev Shed web site or not depends on the value returned by the "confirm" statement.
So far, so good. At this stage, I demonstrated how to use two key components of the "jQuery" library, that is the $() function and the "ready()" method respectively, to display a couple of message boxes each time a link is clicked by a hypothetical user.
In addition, although all of the practical examples developed so far are fairly simple, they're good enough to illustrate how to assign an event handler to a targeted element within a web document.
However, the "jQuery" library permits you to work easily with many mouse events, not just simple clicks. Therefore, the last section of this introductory tutorial will be focused on demonstrating how to use the library to fire up a function when the mouse is clicked over a web page link.
To learn more about how this will be achieved, you'll have to visit the following section. It's only one click away.