title: CSS3 Selector: select a parent node of a specific node?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1014861/is-there-a-css-parent-selector">Is there a CSS parent selector?</a>  </p>
  </blockquote>
  
  
  
  <p>Hi!</p>
  
  <p>I'm trying to select a parent node of a specific node (with a specific className) to apply some CSS style to it.</p>
  
  <p>As far as I know, there only exist CSS3 selector operands for child elements, descendant, following nodes etc... So only some "forward" selection in the DOM document is possible. When the selector applies to some section in the DOM document, always the <em>last</em> element the selector describes, is being selected. Am I wrong? I hope so!</p>
  
  <p>How do you select the first <code>&lt;div&gt;</code> element in the following example? Let's say that there may exist a lot of other <code>&lt;div&gt;</code>s containing <code>&lt;p&gt;</code>s and I only want to select the <code>&lt;div&gt;</code>s containing a <code>p.foo</code> but not <code>p.bar</code>. Note that I want to select the <code>&lt;div&gt;</code> rather than the <code>&lt;p&gt;</code>!</p>
  
  <pre><code>&lt;div&gt;
      &lt;h1&gt;Test&lt;/h1&gt;
      &lt;p class="foo"&gt;Some text&lt;/p&gt;
  &lt;/div&gt;
  &lt;div&gt;
      &lt;h1&gt;Test 2&lt;/h1&gt;
      &lt;p class="bar"&gt;Some other text&lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Thanks in advance!</p>