Method first

The first method selects the first element found.

Syntax

javascript.first();

Example

Let's find all the paragraphs, then select the first one from those found and assign it the text '!':

html<p>text</p>
<p>text</p>
<p>text</p>
javascript$('p').first().text('!');

HTML the code will look like this:

html<p>!</p>
<p>text</p>
<p>text</p>

See also

  • method last,
    which receives the last element
  • method eq,
    which gets the element with a specific number