How can I use CSS to select the “a” tag in the following layout?

I have the following html snippet:

    <select class="error"></select>
    <label class="error"></label>

I need to select the "a" tag with CSS. Is this possible?

I am trying to select the "a" tag. The error class is dynamically injected via javascript. I want to have a static css rule that makes the "a" tag red.

I am only interested in a CSS approach using selectors. If this is not possible, I do not need help with alternative approaches.

~~~~~~~~~~~~~~ EDIT: ~~~~~~~~~~~~~~

The only thing that separates this "a" tag from other "a" tags is the presence of the error class elements following it. The error class is dynamically applied. I do not want to select other "a" tags that do not have an error class following it. I only want to select this "a" tag when it is followed by the error class.

~~~~~~~~~ EDIT AGAIN: ~~~~~~~~~

I explained that poorly. I was hoping that I could select the first child (or something) of all divs that contain the error class.


It is not possible. CSS has no tools for selecting an element on the basis of its siblings after it. Even CSS Selectors 4 (which contains many proposed, but not approved or implemented, additions to selectors) lacks such a feature. (If it will ever be added, I suppose it would be called “preceding-sibling combinator”.)

Need Your Help

How to sort dictionaries of objects by attribute value in python?

python dictionary attributes operator-keyword sorted

I would like to iterate over a dictionary of objects in an atribute sorted way

SBT assembly jar exclusion

jar sbt sbt-assembly

Im using spark (in java API) and require a single jar that can be pushed to the cluster, however the jar itself should not include spark. The app that deploys the jobs of course should include spar...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.