jquery Traversing ancestors

using jquery method you can easily traverse up the dom tree to find ancestors of an elemen. simply an ancestors ia a great-grandparent ,parent, grandparent and so on.

the jquery language provide some methods for traversing up the dom tree-

  • jquery parent() method
  • jquery parents() method
  • jquery prentsuntil() method

jquery parent() method

the jquery .parent() method get the parent of each element in the current set of matched elements.

the jquery parent method syntax :-

(selector).parent (selector )
parameterdescription
selectorrequired. specifies a selector to match elements against.

the jquery parent method example


jquery parents() method

the .parents() method get the ancestors of each element in the set of matched elements.

the jquery parents method syntax :-

(selector).parents (selector )

parameterdescription
selectorrequired. specifies a selector to match elements against.

jquery parents method example