jquery Source Analysis---building jquery objects

Source: Internet
Author: User

2.1, jquery design concept

Before using jquery, we all ask what is jquery? jquery is a class library, like the Prototype,mootools class library, for the web of JS development to provide auxiliary functions. So why do you choose jquery? Prior to the advent of jquery, Prototype,yui is a very mature JS framework, but each has its own characteristics. Why discard them and use the Up-and-comer jquery, what are the outstanding features that attract developers?

To answer this question, we need to understand the design concept of jquery. Recall or imagine how we use JS in Web development? Most of the time is the use of getElementById in the DOM document to find the DOM element, and then value or set the value, using innerHTML to take it or set its contents, or to monitor the event (such as Click), in the control style, we will be the height, Width,display and other changes, to achieve visual effects, for Ajax, but also to take the data in the page of an element to add content.

In summary, we are working on the DOM elements. This element may be one or more. This element may be a Document,window or DOM element. So our task is two parts, one is to find the DOM elements, and the other is to manipulate the DOM elements.

For the use of proficiency, whether the use of direct lookup such as getElementById or the use of such as element.lastchild such as indirect lookup is not difficult, for DOM elements, Dom is also very rich in the operation, it is not difficult to use? So what does it take to be a class library? One of the hardest problems is the compatibility of browsers. All JS framework to solve this problem, while simplifying the JS itself with the operation.

Prototype can be said to create a JS class library of the precedent, give us a refreshing feeling. It solves the problem of the compatibility of most browsers. At the same time simplifies the original function name long difficult to remember often write wrong problem (use $ (xx) instead of getElementById), provides the Ajax access way, expands array,object,function,event and so on JS native object.

But these still do not meet the needs of development, such as looking at DOM elements in the DOM tree, only through the ID of the element, but we want more convenient search methods, but also want to have a unified portal, not too extensive, learning curve too high or difficult to use.

This is where jquery starts, unifying everything in the jquery object. Using jquery is the use of jquery objects. In fact, jquery's groundbreaking work is just like its name: query. Its powerful search function has eclipsed all frameworks.

jquery is essentially a query. It also provides the ability to manipulate the elements that are found on the basis of the query. So jquery is the unification of queries and operations. The query is the entry and the operation is the result.

jquery can also be divided into two parts in implementation, part of the static method of jquery, or a utility method or tool method, which is directly referenced through the jquery namespace of jquery.xxx (). The second part is a jquery instance method that generates a jquery instance through jquery (XX) or $ (xx), and then references the method through this instance. Most of the methods in this section are done from the static method proxy to complete the function. True functional operations are implemented in the static method of jquery.

These features are subdivided into the following sections:

1, Selector, find elements. This lookup contains not only the CSS Selector features based on CSS1~CSS3, but also some of the features it extends to direct lookup or indirect lookup.

2, the properties of the DOM element operation. Dom elements can be labeled as HTML, and actions on attributes operate on the properties of a label. This attribute operation contains additions, modifications, deletions, values, and so on.

3, the DOM elements of the CSS style operation. CSS is the effect of controlling the display of a page. To the CSS operation that must include the height, width, display and other commonly used CSS features.

4, the operation of Ajax. The function of Ajax is to fetch data from the server asynchronously and then do the related operations.

5, the operation of the event. The compatibility of the event was handled uniformly.

6, Animation (Fx) operation. Can be viewed as an extension on a CSS style.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.