jQuery children() Method

Last Updated:

jQuery children() Method

The jQuery children() method returns all direct children of the selected element.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>jQuery children() Method</h1> <div> <p>This is paragraph.</p> <a href="/css">Learn CSS</a> </div> <script> $(document).ready(function(){ $("div").children().css("color", "red"); }); </script> </body> </html>

Syntax

$(selector).children(elem);

Parameter Values

Value Type Explanation
elem Optional Specifies a string containing a element / selector expression to match elements against.

Browser Support

Devicedesktopmobile
Browsergoogle chromesafarifirefoxinternet Exploreredgeoperagoogle chromesafarifirefoxedgeoperaandroid webviewsamsung internet
children()YesYesYesYesYesYesYesYesYesYesYesYesYes

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>jQuery children() Method</h1> <div> <p>This is paragraph.</p> <a href="/css">Learn CSS</a> </div> <script> $(document).ready(function(){ $("div").children("a").css("color", "red"); }); </script> </body> </html>

Share this Page

Meet the Author