user104966
user104966

Reputation: 41

Locating tag by its text using css

How would you get the following tag using CSS?

<p>You can only use the text inside the tag</p>

As in xpath I'd use the following:

//p[contains(text(), "inside the tag")

PS: I can't close the xpath, it tries to auto complete with code... :S

Upvotes: 1

Views: 359

Answers (2)

user104966
user104966

Reputation: 41

This is what I was looking for!

p:contains("inside the tag")

Upvotes: 3

John G
John G

Reputation: 3533

I believe CSS3 selectors can only filter attributes, not the text within tags. So you could do something like a[href~="aspx"] to match links to aspx pages, but that's as far as content-based matching can go.

For what you want to do, you'll probably have to use javascript or server-side processing.

Have a look at quirksmode and W3 for more information.

Upvotes: 4

Related Questions