What does the chain programming of jquery mean by implicit iteration?

Source: Internet
Author: User
Tags ming

Chained Programming

1. Benefits

"In a word, chained programming can save a lot of repetitive code. ”

the words What do you mean? Let me give you an example.

/* Set two properties of the Obj object */

The common practice is this

Obj.name = ' Xiao Ming ';

Obj.age = 155;

Chained programming is the case.

Obj.name (' Xiao Ming '). Age (15);

2. Note

Chained Programming Note:

$ (' div '). html (' Set Value '). Val (' Set value '); this is possible.

But $ (' div '). html (). Text () is wrong, because getting a value returns a string instead of the object itself, so you can't chain-program.

3. broken chain of the whole

Chain programming must pay attention to when the "destruction" of the chain, the current object delivery, if the transmission is broken, then continue to chain programming will have unexpected results! Nextall (), Prevall (), Sibilings ()

How to resolve: Call the End () method. (Returns the object before the chain is destroyed.) )

Implicit Iteration

In the example above

$ (' #btn '). Click (function () {

Implicit iteration:

$ (' P '). Text (' for New China '). CSS (' background ', ' blue ');         

});

Gets the element p, getElementsByTagName found in the traditional DOM notation that no method name elements is a plural form.

In other words, a collection should be obtained.

We know the properties of the elements in the set, the necessary iterations. (It's just a walk.)

But there is no need for traversal in jquery to be set directly. Why is it? This is the implicit iteration chant.

What does the chain programming of jquery mean by implicit iteration?

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.