Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery, how to check if a specific ID is a child of an other id?

I have a specific id ("mysubid"), now I want to check if this element (this id) is in a child path of an other id ("mymainid").

Is there an easy way to do this or will I go upwards, element by element, to see if the element is in a child path.

By child path I am talking about something like this:

A > B > C > D

So D is in the Child Path of A,B and C

like image 910
Chris Avatar asked Nov 29 '22 05:11

Chris


1 Answers

You all are making this very complicated. Use the descendant selector:

if ($('#mymainid #mysubid').length) {
    // #mysubid is inside #mymainid
}
like image 61
kevingessner Avatar answered Dec 09 '22 15:12

kevingessner