Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a CSS selector for elements containing certain text?

I am looking for a CSS selector for the following table:

Peter    | male    | 34 Susanne  | female  | 12 

Is there any selector to match all TDs containing "male"?

like image 798
jantimon Avatar asked Oct 05 '09 14:10

jantimon


People also ask

How do I get CSS selector for text?

Step 1: Type “css=input[type='submit']” i.e. the locator value in the target box in the Selenium IDE and click on the Find Button. Notice that the “Sign in” button would be highlighted. Attribute – It is the attribute we want to use to create CSS Selector. It can value, type, name etc.

How do you select certain elements in CSS?

The CSS id Selector The id of an element is unique within a page, so the id selector is used to select one unique element! To select an element with a specific id, write a hash (#) character, followed by the id of the element.

Can we use contains in CSS selector?

A custom built CSS selector for more advanced users can be built using the "contains" selector. The "contains" selector is useful in cases where we are looking for an element that "contains" some text (case sensitive).

How do I target a specific paragraph in CSS?

You can use nth-of-type selector to select second p element. By using #testing in the selector, you're only targeting the elements that are inside of the #testing element. So, you don't have to worry about the p elements elsewhere.


2 Answers

If I read the specification correctly, no.

You can match on an element, the name of an attribute in the element, and the value of a named attribute in an element. I don't see anything for matching content within an element, though.

like image 174
Dean J Avatar answered Dec 11 '22 22:12

Dean J


Looks like they were thinking about it for the CSS3 spec but it didn't make the cut.

:contains() CSS3 selector http://www.w3.org/TR/css3-selectors/#content-selectors

like image 42
Jeff Beaman Avatar answered Dec 11 '22 23:12

Jeff Beaman