72 of 119 menu

The each method

The each method calls the given function for each element of the set. Unlike the similar map method, which returns a newly formed set of different elements and objects, the each method returns the original set of elements.

Syntax

The elements themselves are available in the function, in the variable this, and their ordinal numbers in the set — in the variable index:

$(selector).each(function(index, elem));

Example

Let's display the contents of each paragraph sequentially using the each and text methods:

<p>text1</p> <p>text2</p> <p>text3</p> $('.www').each( function() { console.log($(this).text()); // will bring out 'text1', 'text2' And and 'text3' } );

See also

  • method filter,
    which filters elements by a specific selector
  • method map,
    which calls a given function for each element of a set
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline