jquery Source Learning Notes (1)

Source: Internet
Author: User
Tags tag name

Learn the jquery source code on the Web, do some small research on notes.

1th Chapter Node Traversal

The 2nd Chapter document processing

3rd Chapter Element operation

4th Chapter Style Operation

5th Chapter Event System

The 6th Chapter Data interaction

7th Chapter Animation Engine

First look at the catalogue, you can probably find out how this is said Qaq.

What we are learning today is node traversal.

The objects traversed are: 1 Ancestors 2 Brothers 3 descendants 4 filter

Let's look at our ancestors first.

The. Parent () method allows us to search the DOM tree for the parent elements of these elements, to match elements from an orderly upward, and to create a new JQuery object based on the matching elements.

The. Parents () and. Parent () methods are similar, but the latter only perform a single-level DOM tree Lookup

The. Parentsuntil () method will search through the predecessors of all these elements until it encounters an element that matches the parameter before it stops. The returned jquery object contains all of the found predecessor elements, in addition to the one that matches the. Parentsuntil () selector.

In simple terms. Parent () is a parent element, the most recent one,. Parents is all the parent element: Parentsuntil () is a search termination point you can pass in.

Then take a look at how it's written (see nodetype:http://www.w3school.com.cn/jsref/prop_node_nodetype.asp first)

functionParent (elem) {varParent =Elem.parentnode;
Returns null if the Father node is documentfragmentreturnParent && Parent.nodetype!== 11? Parent:NULL;}functionparents (elem) {varmatched = [];
If the element has a parent element and the element is not the root node while((Elem = elem[' parentnode ') && elem.nodetype!== 9 ) {
If the element type is added to the arrayif(Elem.nodetype = = 1) {Matched.push (elem); } } returnmatched;}functionParentsuntil (Elem, filter) {varmatched =[], Until,
If no filter is defined, set truncate to false truncate= Filter!==undefined; while((Elem = elem[' parentnode ') && elem.nodetype!== 9) { if(Elem.nodetype = = 1) {
If a filter is set, perform the followingif(truncate) {
element name lowercase alignment is a terminating elementif(elem.nodeName.toLowerCase () = =filter) { Break; }} matched.push (Elem); } } returnmatched;}

Brother Node

//Defines a common function that reduces duplicate code.
Elem Central Element, dir is the type of element to look for, until is the tag name or class name of the terminating element
functiondir (Elem, dir, until) {varmatched =[], truncate= until!==undefined; while((Elem = Elem[dir]) && Elem.nodetype!== 9) { if(Elem.nodetype = = 1) { if(truncate) {if(elem.nodeName.toLowerCase () = = until | | elem.classname = =until) { Break; }} matched.push (Elem); } } returnmatched;} All the brother nodes behindfunctionNextall (elem) {returnDir (Elem, "nextSibling");}
All the previous sibling nodesfunctionPrevall (elem) {returnDir (Elem, "previoussibling");}
functionNextuntil (Elem, until) {returnDir (Elem, "nextSibling", until);}functionPrevuntil (Elem, until) {returnDir (Elem, "previoussibling", until);}
function sibling (cur, dir) {  while((cur = cur[dir]) && cur.nodetype!== 1) {}   ret Urn  cur;} function Next (elem) {  return sibling (Elem, "nextSibling");} function prev (elem) {  return sibling (Elem, "previoussibling");}

. Next () to get the next sibling of their kin

. Prev () to get his own kindred of the last fellow

. siblings () to acquire all the countrymen of their kindred except their own

Feel a little puzzled this siblings ... Let's study here today.

jquery Source Learning Notes (1)

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.