Search code examples
jquerydomtraversal

How can I know if an element is a direct child of the body using jQuery


I want to perform some action on elements that are not direct child of the body. How can I check a particular element to know whether its partent is the body.

Thanks!


Solution

  • You can test the tag name this way :

    jQuery('#urDivId').parent().is('body')