I have fields with multiple classes. I want to use one of those classes as a selector, how do I do this?
generic example:
<input id="from"/><div class="error from">errormessage</div>
<input id="to"/>
<div><input id="when" /></div><div class="error when">errormessage</div>
Because ther is a div.error with the class from, I want to add a certain class to input#from and the same goes for the input called when. Note that “when” is wrapped in a div. Several variations like this are necessary for the page. Therefore, tree-traversal is not a suitable solution.
For updated question:
I think this is what you’re after, since the element since to be a previous sibling or contained in one:
You can test it out here.
For previous question:
Use the
.classselector, like this:You can also select elements that only have multiple classes by chaining them, for example:
Would only select elements that had all 3 classes.