9951 explained code solutions for 126 technologies


jqueryHow do I select the first child element using jQuery?


The first child element of an element can be selected using jQuery with the :first-child selector.

Example code

$('p:first-child')

This will select the first <p> element inside the parent element.

The code can be broken down into the following parts:

  • $(': This is the jQuery selector function.
  • p: This is the element type that will be selected.
  • :first-child: This is the selector used to select the first child element.
  • '): This is the closing parenthesis of the selector function.

Helpful links

Edit this code on GitHub