3

These two [class^=test] and [class|=test] matches the same elements as I see.

Is there any real difference or case why should I use one over the other?

stackoverflow
  • 1,303
  • 2
  • 21
  • 36

1 Answers1

6
[class^="test"]

The above selects all elements that starts with class "test", it will fail to find if the test is second class.

But:

[class|="test"]

finding elements that matches class, won't show you if the class is "testing" but will find if the class is "test-ing", the above one will match both. Also , it will fail to find if the test is second class.

[class|="test-"]

And this case will only accept "test-" and won't accept "test-ing" or a string which starts with "test-", e.g., "test-ing".

Anson
  • 489
  • 7
  • 12
Ultrazz008
  • 1,678
  • 1
  • 13
  • 26