How to get parent of parent in jQuery

how to get parent of parent in jQuery – You can use the following method to get parent of in jquery. In this example we have explained the method to get parent of parent. There are two methods which we can use to get this solution – parent and closest.

How to get parent of parent in jquery

Suppose you want to access the id of parent of parent element of a div. Here is jQuery code you can use to find this fix –

$(this).closest('div').closest('div').attr('id');

$(this).parents('div').parents('div').attr('id'); or you can use the class of the parent of the parent

$(this).closest(".className");

Advertisements

Add Comment

📖 Read More