 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
jQuery :first-child Selector
The :first-child selector in jQuery is used to select all elements, which are the first child of their parent.
Syntax
The syntax is as follows −
$(":first-child")  Example
Let us now see an example to implement the :first-child() selector −
<!DOCTYPE html> <html> <head> <style>    .demo {       background-color: red;       color: white;       font-size: 16px;       border: 2px blue dashed;    } </style> <script src="https://code.jquery.com/jquery-3.4.1.js"></script> <script>    $(document).ready(function(){       $("p:first-child").addClass("demo");    }); </script> </head> <body> <p>This is the first line!</p> <p>This is the second line!</p> <p>This is the third line!</p> <hr> <div> <p>One</p> <p>Two</p> <p>Three</p> <p>Four</p> </div> <hr> <p>This is the last line.</p> </body> </html> Output
This will produce the following output −

Advertisements
 