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 use jQuery to check if an element is visible?
- How do I use jQuery ZTree to create a hierarchical tree structure?
- How do I download a zip file using jQuery?
- How can I get the y position of an element using jQuery?
- How can I use JQuery with Yii2?
- How do I use jQuery to detect window resize events?
- How can I parse XML data using jQuery?
- How can I use jQuery in WordPress?
- How do I use jQuery to validate a form?
- How can I convert jQuery code to vanilla JavaScript?
See more codes...