1

I need to select a <p> element that has a nested <a> with a specific class.

The <a> is not always a child of the <p> and may instead be a grandchild. For example:

<p>some text<span><a href="#" class="myclass f5">link</a></span></p>

I need to select the <p> element if it has an <a> with the class f5 anywhere inside.

BoltClock
  • 630,065
  • 150
  • 1,295
  • 1,284
Dmitri Snytkine
  • 1,086
  • 1
  • 8
  • 14
  • possible duplicate of [Is there a CSS parent selector?](http://stackoverflow.com/questions/1014861/is-there-a-css-parent-selector) – cimmanon May 27 '15 at 10:13

1 Answers1

6

this isn't possible with a css selector (theres nothing like a parent-selector).

maybe you can work around this with javascript - in jquery, for example, you should get your paragraphs with $('p:has(a.f5)') (and then you're free to .addClass() or set .css() on this elements directly).

EDIT::
you might also want to take a look at this other questions on SO (and next time: search before you ask):

Community
  • 1
  • 1
oezi
  • 47,789
  • 10
  • 94
  • 113