Finding the Parent or Ancestors of Selected Items

$("div#menu").parent();   //selects the <div> element with id="menu" and   // then finds its immediate parent $("#data").parents("div");   //selects the element with id="data" and then   //returns a set with all <div> ancestors $("#data").parentsUntil("#menu");   //selects the parents of #data until   //it finds the one with id="#menu"

The .parent([selector]) method returns a jQuery object representing the immediate parent objects of each of the elements represented in the current set. An optional selector argument allows you to limit the results to those parents matching the selector.

The .parents([selector]) method returns a jQuery object representing the ancestors ...

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.