Home    Articles

 

How to find the id of the parent element in jQuery

 

! In order to find the parent id of an element you can do it in two ways:

First option:
…this will find the parent attribute “id”.

 $(this).parent().attr("id");

Second option:
…this option will find the id of the closest element …that is the parent.

var id = $([this/child div id or class]).closest("div").attr("id");

ps: i will use the first one. :)

Enjoy.

by