Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"AND" operator in CSS selectors

I’m pretty familiar with xpath but not so much using css selectors in order to find a certain element.

I know this xpath //input[contains(@value, "15.02.2022") would result into this css-selector input[value*="15.02.2022"].

But how would you translate this xpath //input[contains(@value, "15.02.2022") and contains(@value, "123")] into a css selector?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How would you use the "AND" operator to find a certain element?

>Solution :

Generally speaking, you aren’t restricted to only one selector of a kind (with the notable exception of element selectors, for obvious reasons):

.a.b {
    color: green;
}
<span class="a">Only A</span>
<span class="b">Only B</span>
<span class="a b">Both A and B</span>

Attribute selectors work the same way:

input[value*="15.02.2022"][value*="123"] {
    color: green;
}
<input value="Only 15.02.2022">
<input value="Only 123">
<input value="Both 15.02.2022 and 123">
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading