For example, suppose we have an HTML that is given below:
<div id="ParentID"> <div id="childID">Get the Parent ID</div> </div>
You can see that we have a parent element with ID “parentID” and inside it, there is a child element having the ID “childID”. Now we have to get the parent ID of the child element with the ID “childID”.
Using the above code, we are showing the ID of the parent element as an alert text.
Now if you run the code, you can see the ID of the parent element, in our case, we can see “ParentID” in the alert text.