When you want to apply the style to the child element of the list, div, etc. jQuery child element selector is the best way to select the child element of any parent. You can select all direct children or the specified child of the parent element.
jQuery Child Element Selector by Tag Name
To select the child of the parent element, you have to specify the tag name of both the elements with the parent > child combination.
Use the below syntax of jQuery to get the way to write the combination.
$("span > p").css('color','green');
<p>This is the paragraph</p>
This is the paragraph
The above example applies the style color property to the inner element of the span. You can also apply the style to the list elements using the ul > li combination of the selector. To see the example, learn it with the below section.
Get Children with its Class Name Using jQuery
In addition to the above tag name selector, you can also select the inner item using its class name with parent > child selector. For this, you have to use the value of the class attribute of the parent and child element.
See the syntax below which contains the class name with the parent > child selector.
$("ul.my-list > li.my-red-list").css('color','red');
<li>Welcome to my website Tutorialdeep!</li>
<li>See live examples to understand the topic.</li>
<li class="my-red-list">Free download to quickstart.</li>
<li>Learn jQuery with Tutorialdeep.</li>
- Welcome to my website Tutorialdeep!
- See live examples to understand the topic.
- Free download to quickstart.
- Learn jQuery with Tutorialdeep.
The above example applies the red color to the third child of the list element.