<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet type='text/xsl' href='docs-1.7.xsl'?>
<entries><entry type='selector' name="parent" return="">
  <sample>:parent</sample>
  <signature><added>1.0</added> </signature>
  <desc>Select all elements that are the parent of another element, including text nodes.</desc>
  <longdesc>
    <p>This is the inverse of <code>:empty</code>. </p>
<p>One important thing to note regarding the use of <code>:parent</code> (and <code>:empty</code>) is that child elements include text nodes.</p>
<p>The W3C recommends that the <code>&lt;p&gt;</code> element have at least one child node, even if that child is merely text (see <a href="http://www.w3.org/TR/html401/struct/text.html#edef-P">http://www.w3.org/TR/html401/struct/text.html#edef-P</a>). Some other elements, on the other hand, are empty (i.e. have no children) by definition:<code> &lt;input&gt;</code>, <code>&lt;img&gt;</code>, <code>&lt;br&gt;</code>, and <code>&lt;hr&gt;</code>, for example.</p>

  </longdesc>
    <example>
      <desc>Finds all tds with children, including text.</desc>
      <code><![CDATA[$("td:parent").fadeTo(1500, 0.3);]]></code>
<css><![CDATA[
  td { width:40px; background:green; }
  ]]></css>
<html><![CDATA[<table border="1">

  <tr><td>Value 1</td><td></td></tr>
  <tr><td>Value 2</td><td></td></tr>

</table>]]></html>
    </example>
<category name="Content Filter"/>
<category name="jQuery Extensions"/>
<category name="Version 1.0"/>
<note type="additional">Because <code>:parent</code> is a jQuery extension and not part of the CSS specification, queries using <code>:parent</code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. To achieve the best performance when using <code>:parent</code> to select elements, first select the elements using a pure CSS selector, then use <a href="http://api.jquery.com/filter/"><code>.filter(":parent")</code></a>.</note></entry><entry type='method' name="parent" return="jQuery">
              <signature>
                <added>1.0</added>
                <argument name="selector" optional="true" type="Selector">
                    <desc>A string containing a selector expression to match elements against.</desc>
                </argument>
              </signature>
              <desc>Get the parent of each element in the current set of matched elements, optionally filtered by a selector.</desc>
              <longdesc><p>Given a jQuery object that represents a set of DOM elements, the <code>.parent()</code> method allows us to search through the parents of these elements in the DOM tree and construct a new jQuery object from the matching elements. The <code>.parents()</code> and <code>.parent()</code> methods are similar, except that the latter only travels a single level up the DOM tree.</p>
<p>The method optionally accepts a selector expression of the same type that we can pass to the <code>$()</code> function. If the selector is supplied, the elements will be filtered by testing whether they match it.</p>
<p>Consider a page with a basic nested list on it:</p>
<pre>
&lt;ul class="level-1"&gt;
  &lt;li class="item-i"&gt;I&lt;/li&gt;
  &lt;li class="item-ii"&gt;II
    &lt;ul class="level-2"&gt;
      &lt;li class="item-a"&gt;A&lt;/li&gt;
      &lt;li class="item-b"&gt;B
        &lt;ul class="level-3"&gt;
          &lt;li class="item-1"&gt;1&lt;/li&gt;
          &lt;li class="item-2"&gt;2&lt;/li&gt;
          &lt;li class="item-3"&gt;3&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li class="item-c"&gt;C&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li class="item-iii"&gt;III&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>If we begin at item A, we can find its parents:</p>
<pre>$('li.item-a').parent().css('background-color', 'red');</pre>
<p>The result of this call is a red background for the level-2 list. Since we do not supply a selector expression, the parent element is unequivocally included as part of the object. If we had supplied one, the element would be tested for a match before it was included.</p></longdesc>
                <example>
                    <desc>Shows the parent of each element as (parent > child).  Check the View Source to see the raw html.</desc>
                    <code><![CDATA[

    $("*", document.body).each(function () {
      var parentTag = $(this).parent().get(0).tagName;
      $(this).prepend(document.createTextNode(parentTag + " > "));
    });
]]></code>
                    <css><![CDATA[
  div,p { margin:10px; }
  ]]></css>
                    <html><![CDATA[<div>div,
    <span>span, </span>
    <b>b </b>

  </div>
  <p>p,
    <span>span,
      <em>em </em>
    </span>
  </p>

  <div>div,
    <strong>strong,
      <span>span, </span>
      <em>em,
        <b>b, </b>
      </em>

    </strong>
    <b>b </b>
  </div>]]></html>
                </example>
                <example>
                    <desc>Find the parent element of each paragraph with a class "selected".</desc>
                    <code><![CDATA[$("p").parent(".selected").css("background", "yellow");]]></code>
                    <html><![CDATA[<div><p>Hello</p></div>

  <div class="selected"><p>Hello Again</p></div>
]]></html>
                </example>
            <category name="Tree Traversal"/>
<category name="Version 1.0"/>
</entry></entries>