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
  • 75,784
  • 13
  • 108
  • 129
thelolcat
  • 10,155
  • 19
  • 59
  • 100

1 Answers1

1

Yes, you can!

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

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

Caio Tarifa
  • 5,873
  • 11
  • 45
  • 70
  • 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