Is there any direct way in JavaScript or jQuery to check if an element is within another one.
I\'m not referring to the $(this).parent
as the element I wish
With jQuery >=1.4 (2010) you can use the very fast function jQuery.contains()
This static method works with DOM elements, not with jQuery elements and returns true
or false
.
jQuery.contains( container, descendant )
Example: To check if a element is in the document you could do this:
jQuery.contains( document.body, myElement )