jQuery parent method

If you want to apply the CSS to the parent element of the selected, you can use the jQuery parent method to do this. The method requires only the selector to select the element to which you want to apply the CSS to the parent.

You can use id’s or class name to select the HTML element. You can use the other methods like the jQuery addClass method to add the class and other methods with the jQuery parent method as given below.

How to Find the Parent of HTML Element Using jQuery parent() Method

You have to follow the syntax given below.
Syntax

See the example given below to learn the working of the jQuery parent method.

Example

Test it Live

Output

  • Welcome to Tutorialdeep Web Tutorial!
  • Learn jQuery With Working Examples.

The above example add the class to the parent of the selected HTML element. After you click the button given above, the parent() add the class to the parent Element and so apply the CSS comes with the class.