Skip to main content
Home / Code Snippets / jQuery Code Snippets / Check if Element is inside Another Specific Element

Check if Element is inside Another Specific Element

Replace the first selector with the child you are testing and the second selector with the parent you are testing for.

if ( $(".child-element").parents("#main-nav").length == 1 ) { 

   // YES, the child element is inside the parent

} else {
 
   // NO, it is not inside

}