1

I'm trying to determine the style of a div by going by what is in it. If the content is '0', it should have color: red, and if not, fall back to the usual color.

I've found there used to be :contains(value), but that doesn't exist anymore. Is there any replacement I can use for this in css?

Thanks in advance.

3
  • You could read the innerText of the div, if all you're looking for is a single character. You could do that with a small bit of Javascript. But setting the class with server side code is usually the sanest approach. Commented Jul 22, 2013 at 14:31
  • @KristianVitozev this is not a duplicate of that question at all. Commented Jul 22, 2013 at 14:31
  • 1
    In the existing CSS there is only a possibility to display red '0's in divs that have no content at all: jsfiddle.net/cKnFC. Commented Jul 22, 2013 at 18:39

1 Answer 1

4

No, there isn't. If CSS was going to have a content selector, it would have kept :contains().

For what it's worth, jQuery implements :contains(), so if you're using it already you can apply styles with it instead.

Sign up to request clarification or add additional context in comments.

1 Comment

I was afraid that might be the answer. Thanks anyway!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.