jquery each function break and continue function

Source: Internet
Author: User
$ ('. Container '). each (function (i) {
if ($ (this). attr (' name ') = = "Continue") {
return///implement Continue function
}else if ($ (this). attr (' name ') = = "Break") {
Return false;//implement Break function
}
})

Look at the jquery each function

When you want to use return true for this function in each, you simply let each continue and
There's no interruption to each, so the function can't return.


Each of the jquery works well, except for loops that use it instead of web effects

function MethodOne () {
....
$.each (Array,function () {
if (condition set) {
return true;
}
});
....
}


Break Continue instance

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

So, you can write the following code:

$ (' Li '). each (function (index) {
if (index==2) return true;
if (index==4) return false;
$ (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.