0

If I have this markup:

<label>Email Address:</label>
<input class="validation-failed" type="text"></input>

How do I select the label, only if the input has the class .validation-failed?

Joshua Soileau
  • 2,933
  • 9
  • 40
  • 51
  • 1
    You can't. There's no previous sibling selector in CSS yet. – j08691 Mar 14 '14 at 13:32
  • 1
    What @j08691 said. Also it's worth noting that in CSS level 4 selectors you can [determine the subject of a selector](http://dev.w3.org/csswg/selectors4/#subject) by `!` mark as `!label + .validation-failed`. But none of web browsers have implemented this. – Hashem Qolami Mar 14 '14 at 13:35

1 Answers1

0

As mentioned in comments there is no pure css solution,

There is a jQuery solution using the .prev() method, ref: https://api.jquery.com/prev/

gimiarn1801
  • 131
  • 2
  • 7