Open In App

How to apply css property to a child element using JQuery?

Last Updated : 23 Sep, 2021
Comments
Improve
Suggest changes
1 Like
Like
Report

The task is to apply CSS property to a child element using jQuery. To do that, first we select the child element with the help of children() method in jQuery and then apply CSS property to it with the help of css() method in jQuery.

Syntax:

// Note : children method selects the direct child to parent
$(selector).children("selector").css("property-name","value")

Example 1

Output: 

Before Clicking the Button:

After Clicking the Button:

We can also apply CSS property to grand-child and any descendants to parent with the help of find() method in jQuery.

Syntax:

$(selector).find("descendants-name").css("property-name","value");

Example 2:

Output:

Before clicking the button:

After clicking the button:


Next Article

Similar Reads