jQuery parent > child Selector

jQuery | parent > child Selector: Learn about the parent > child Selector with its usages, syntax, examples.
Submitted by Pratishtha Saxena, on December 02, 2022

parent > child Selector

In jQuery, selectors are a parameter through which we can select the HTML element. Selectors can comprise – class names, ids, tag names, attributes, etc. Basically, by using selectors, the appropriate HTML-DOM element can be selected and hence performed actions on it. Here, we are discussing about the jQuery parent > child Selector.

The jQuery parent > child selector allows us to select the direct child of the specified parent tag. If the parent tag specified is 'p' and the child specified is 'span', then all the direct children of the parent tag will be selected.

This selector helps in selection of all the similar elements within a tag in a go. The parent and child here are referred to as the tag name to be considered respectively.

parent > child Selector Syntax

$('parent > child');

Once the elements are selected, you can access them and perform the actions that you want to perform on them. The example given below shows the selection of the specific child elements of the parent element on click by passing the appropriate selector.

jQuery parent > child Selector Example

<!DOCTYPE html>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
    <h2>jQuery - Parent > Child Selector</h2>
    <p>Click the button to get the direct child element of the parent tag specified.</p>
    <button>Click Here</button>
      <p>Welcome to Include Help !</p>
      <span>This is a jQuery Tutorial.</span>
      <p>We are discussing about the parent > child selector.</p>
      <p>Thanks for Visiting !</p>
  <script type="text/javascript">
            $("div > p").css({"color":"red", "font-weight":"bold"});


Example 1: jQuery parent > child Selector

All jQuery Examples

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.