Codelab Editor
Free Online HTML Editor
Run
Learn jQuery
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>jQuery children() – Get Immediate Children Elements</title> <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> <style> body { font-family: Arial, sans-serif; background: #f9f9f9; padding: 30px; } h2 { color: #333; } .description { margin-bottom: 20px; color: #666; } .parent-box { border: 2px solid #999; padding: 15px; background: #fff; width: 400px; cursor: pointer; } .child { margin: 5px 0; padding: 10px; background: #e7f3ff; border: 1px solid #99c; } .nested-wrapper { margin: 5px 0; padding: 20px; background: #33333355; border: 1px solid #99c; } .highlight { background: #ff3f3f33; border-color: #ff3f3f; } </style> </head> <body> <h2>jQuery children() – Get Immediate Children</h2> <p class="description"> Click the parent box below to highlight only the <strong>direct child</strong> elements using the <kbd>children('.child')</kbd> method. </p> <div class="parent-box"> <div class="child">Child 1</div> <div class="child">Child 2</div> <div class="child">Child 3</div> <!-- Nested child (not direct) --> <div class="nested-wrapper"> <div class="child">Nested Child</div> </div> </div> <script> $(function () { $('.parent-box').on('click', function () { $('.child').removeClass('highlight'); // Clear previous highlights $(this).children().addClass('highlight'); }); }); </script> </body> </html>
Editor Commands
Ctrl
F
Find
Ctrl
G
Find Next
Ctrl
⇧
G
Find Previous
Ctrl
⇧
F
Find & Replace
Ctrl
]
Indent Code Right
Ctrl
[
Indent Code Left
⇧
Tab
Auto Indent Code
Ctrl
/
Line Comment
Ctrl
Alt
/
Block Comment
TutsInsider Actions
Alt
S
Run Code
Ctrl
C
Copy Editor Code
Ctrl
A
Select All Editor Code
Ctrl
S
Save/Download
Ctrl
Alt
X
Rotate
Ctrl
Alt
T
Switch Theme
Ctrl
⇧
C
Open Console
Esc
Close Console