Code Snippet
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
}
:D
Thanks! Clean and Short
if($(' #childElementID' parentElementId).length == 1) { // YES, the child element is inside the parent } else { // NO, it is not inside }Using jQuery context !
missing the coma sorry !
if($(' #childElementID' , parentElementId).length == 1) { // YES, the child element is inside the parent } else { // NO, it is not inside }DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.