jquery Each loop usage

Source: Internet
Author: User

In jquery we will often use each. Because each can loop through the contents of each selection. For example: $ ("P"). each (the function () {$ (this). HTML ("I was changed."); This is the current loop to the P.}; It's very simple to replace all the contents of P. Let's take another look at each. $ ("P"). each (the function (i,dom) {$ (this). HTML (i+ "-" +dom);});

Look at a checkbox using the jquery Each loop

$.each ($ (input:checked), function (i,n) {
alert (N.value); Effective
Alert (N.val ()); Invalid, why is this???
return false;
});

The above operation has the problem, corrects

$.each operations are generic objects, not jquery objects, so n is a DOM element

The jquery object is needed in this way:

$ (input:checked). each (function (i,n) {
Alert ($ (N). Val ()); Here n is to represent the DOM object plus $ to be converted to a jquery object
return false;
});

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.