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
More of Jquery
- How can I get the y position of an element using jQuery?
- How can I use JQuery with Yii2?
- How do I use the jQuery masked input plugin?
- How do I uncheck a checkbox using jQuery?
- How can I convert jQuery code to vanilla JavaScript?
- How can I convert XML data to JSON using jQuery?
- How can I use jQuery to control the visibility of an element?
- How do I use the jQuery UI Datepicker?
- How do I use jQuery to trigger an event?
- How do I use jQuery to toggle an element?
See more codes...