1

Is it possible to select a element that has a class that starts with a string?

There is

 .element[class^="icon-"]{
   ...
 }

but it fails when the class is preceded by another class or whatever :(

James Montagne
  • 77,516
  • 14
  • 110
  • 130
thelolcat
  • 10,995
  • 21
  • 60
  • 102

1 Answers1

1

Yes, you can!

.element[class^='icon-'],
.element[class*=' icon-'] {
  ...
}

See it in action: http://jsfiddle.net/caio/mxUxR/.

Caio Tarifa
  • 5,973
  • 11
  • 46
  • 73
  • 2
    This will, of course, fail if the class is preceded by any of the *other* valid whitespace characters: `\n`, `\r`, `\f`, and `\t`. Otherwise, the general idea is sound. – zzzzBov May 01 '14 at 19:11
  • 1
    @zzzzBov yes, you know a solution to "fix" it? – Caio Tarifa May 01 '14 at 19:18