2

Text can come form different source. After getting text it will display on site. From this text I need to change format of a specific word using CSS. In following example database word have to change:

enter image description here

It is easily done by JavaScript JSFiddle but I need it by CSS not by JavaScript. Any idea?

Khalid Farhan
  • 435
  • 1
  • 3
  • 19
  • 6
    No...CSS can't detect content. JS is your only option unless you wrap each instance of the word in a classed element like a span. – Paulie_D Aug 04 '15 at 14:23
  • Possible duplicate - http://stackoverflow.com/questions/1520429/is-there-a-css-selector-for-elements-containing-certain-text – Paulie_D Aug 04 '15 at 14:25

1 Answers1

2

You cannot select content with CSS, but with jQuery you can. You could wrap "database" in span and then use CSS to style it. For example:

HTML:

<p>A <span class="database">database</span> is a collection of information. In one view <span class="database">database</span> can be classified.</p>

CSS:

.database {color: red;}

When it comes to jQuery:

$( "p:contains('database')" ).css( "color", "red" );

That would probably be the easiest solution, but I personally don't like it.

stormec56
  • 162
  • 2
  • 16