58 of 119 menu

The eq method

The eq method selects the n-th element among those found, i.e. the element with a certain number, for example, the third or fifth. The first element found will have the number 0. The number of an element in a set can be either positive or negative. In the second case, the count is from the end, -1 will be the last element, -2 - the penultimate one, and so on.

Syntax

$(selector).eq(number);

Example

Let's find all the paragraphs, and then color the third one (numbered 2, since the numbering starts from zero) red:

<p>text</p> <p>text</p> <p>text</p> <p>text</p> $('p').eq(2).css('color', 'red');

HTML the code will look like this:

<div class="result"> <p>text</p> <p>text</p> <p style="color: red;">text</p> <p>text</p> </div>

See also

  • method first,
    which receives the first element
  • method last,
    which receives the last element
  • method slice,
    which gets a group of elements in a specified range
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