Jquery-each () method

Source: Internet
Author: User

1, $ (selector). Each (index, element) {}) method iterates through a jquery object and runs the defined function for each matching element.

Index: The index position of the selector.

Element: the current elements.

2, $.each () is used to iterate over algebraic groups and objects. Arrays and array-like objects iterate through a numeric index with a length attribute, from 0 to Length-1. Other objects iterate through their property names.

$.each (array, function (index, value) {})
The callback function of the array is passed one index at a time and the corresponding array value as the parameter.
The callback function of the object passes one key-value pair at a time.
Returns False if the iteration is to be terminated;
Returns a non-false equivalent to continue jumps out of the current iteration and goes to the next iteration.

$(function() {    $("#table2 tr TD"). each (function(index, Element) {$ ( This). MouseOver (function() {alert (index);            Alert (Element). HTML ()); $( This). css ({' Background ': ' #f00 ')}); })    })    vararr1 = [' 0 ', ' 33 ', ' 889 ']; $.each (arr1,function(Index, value) {Alert (index+": " +value); return(Index = = 1); })    varObj1 = {        "Name": ' Roronoa ',        ' Age ': ' 25 '} $.each (Obj1,function(Index, value) {Alert (index+": " +value); })})

Jquery-each () method

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.