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 do I use jQuery ZTree to create a hierarchical tree structure?
- How can I get the y position of an element using jQuery?
- How do I use jQuery to detect window resize events?
- How do I use jQuery to zip files?
- How do I create a jQuery Yes/No dialog?
- How do I prevent XSS attacks when using jQuery?
- How can I use jQuery to check if an element is visible?
- How do I use jQuery Select2 to select multiple options?
- How do I use jQuery to validate an email address?
- How do I use jQuery to trigger an event?
See more codes...