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

javascript$(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:

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

HTML the code will look like this:

html<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