Jquery each function break and continue Function

Source: Internet
Author: User

The break and continue functions of the jquery each function are fortunate to be another breakthrough and continue a jQuery loop. You can break the false loop in which the function returns a jQuery parameter. One can continue to execute but does not specify the return value or any other false return value.

Jquery each function break and continue Function

Fortunately, another breakthrough continues a jquery loop. You can break the false loop in which the function returns a jquery parameter. One can continue to execute but does not specify the return value or any other false return value.

$ ('. Iner'). each (function (I ){
If ($ (this). attr ('name') = "continue "){
Return; // implement the continue Function
} Else if ($ (this). attr ('name') = "break "){
Return false; // implement the break Function
}
})

Let's look at the jquery each function.

When you want to use return true in each to return the function to this function, you only need to let the each continue to execute
The each is not interrupted, so the function cannot return.


In jquery, each is very useful, except for the for loop that replaces webpage special effects.

Function methodone (){
....
$. Each (array, function (){
If (condition true ){
Return true;
}
});
....
}


Break continue instance

Continue: return true;
Break: return false;
Directly returning will also jump out of jquery.

Therefore, you can write the following code:

 

$ ('Lil'). each (function (index ){
If (index = 2) return true;
If (index = 4) return false;
Examples (this).css tutorial ("border", "1px red solid ");
});

 

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.