O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required