This article supporting source code
Brief introduction
jquery gradually emerges from other JavaScript library selections and becomes the best choice for Web developers. It quickly becomes the first choice for programmers who want to simplify client development and quickly and efficiently create rich Internet applications (RIA). With the extensive use of Ria, JavaScript libraries will be used more and more to assist development. RIA is defined (loosely) as a browser-run application that uses Css/javascript/ajax to create a similar appearance to a desktop application. The new features in Firefox, Internet Explorer and Safari's latest releases, and the latest version of Google's newest Chrome browser, are focused on speeding up the internal JavaScript engine of each browser, Its sole purpose is to be more adapted to the RIA that the browser manufacturer designs for the future. These companies think that future Web pages will contain a lot of JavaScript code, so it's important to first develop a mature, bug-free library.
Therefore, as future Web applications continue toward the rich and immersive interface, Web developers are constantly looking for tools to streamline these efforts. There are now a few JavaScript libraries, each with its own pros and cons, as well as its own supporters and opponents. Here, I don't discuss which library features are better because it doesn't have much impact on the end result. The most important thing is which library to use more-the quantity is the most important. Take a look at the Google trend chart for the 4 most popular JavaScript libraries below. It is clear that in the last 6-8 months, JQuery has become the dominant JavaScript library, and this trend is still rising.
Figure 1. Google Trend chart for common JavaScript libraries
The job market has also shown that jQuery is gradually rising to the top of the JavaScript Library of choice. A monster.com result of the study shows that there are 113 positions associated with jQuery, while YUI, ExtJS and MooTools are 67, 19 and 13 respectively.
The first of this jquery series begins with exploring the jquery syntax, and also understands how its functions are invoked. The later sections of this article explore the core functions of the library, and how the library uses its powerful selectors and filters to make DOM traversal easier and clearer. The next article will explain CSS operations, form control, text changes, Ajax simplicity, and animations (everyone's hobby). One of the most interesting features of JQuery is its plug-in architecture, which allows many developers to add new jquery functionality. The last article in this article will introduce a number of powerful plug-ins that can be used to complete the RIA development process.
This series of articles is intended for readers who have JavaScript syntax, CSS syntax, and DOM syntax knowledge.
Basic knowledge
Before delving into the interesting jquery content, let's take a look at some basics-how to install jQuery, and how to make it work properly, and so on. Download the JQuery library from the download section first, and then link to the library like any other external JavaScript file:
Listing 1. How to install JQuery in your code
<script type="text/javascript" src="jquery.js"></script>
Because JQuery invokes or operates DOM objects, it is problematic to use JavaScript code to manipulate these objects directly before the document loads all the page elements. Instead, you don't want to wait for all the elements on the page to load-all images, banner ads, parsing code, and YouTube video previews-to start calling JQuery code. You can compromise the JQuery code in a secure, error-free manner before the document completely loads all the elements on the page, but until all the images, links, and rendering have been completed. Again, all your jQuery code must be in this function on the page, or in its own function. If the JQuery code is not in a function, you cannot place its code in JavaScript code.
Listing 2. How to call the JQuery function correctly
// Incorrect
<script language=JavaScript>
$("div").addClass("a");
</script>
// Correct
$(document).ready(function(){
$("div").addClass("a");
});
// - or -
$(document).ready(function(){
myAddClass();
});
function myAddClass()
{
$("div").addClass("a");
}