Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Selector Clarification: |= vs ^= [duplicate]

According to W3Schools:

[foo|='bar'] "Selects all elements with a [foo] attribute starting with "bar"

and

[foo^='bar'] "Selects every element whose [foo] attribute value begins with "bar"

In my application, I have inputs with IDs "Input-123456", etc.

Selecting them with input[id^="Input-"] works, whereas input[id|='Input-'] returns nothing.

So what's the difference?

like image 823
mhodges Avatar asked Feb 12 '16 19:02

mhodges


People also ask

What are the 3 different kinds of selectors in CSS?

Simple selectors (select elements based on name, id, class) Combinator selectors (select elements based on a specific relationship between them) Pseudo-class selectors (select elements based on a certain state)

Which selector is faster in CSS?

popupbutton is the fastest.


2 Answers

From the "real" reference (W3C):

E[foo^="bar"] an E element whose "foo" attribute value begins exactly with the string "bar"

E[foo|="en"] an E element whose "foo" attribute has a hyphen-separated list of values beginning (from the left) with "en"

Always go to the actual standard when there appears to be an inconsistency. I tend to avoid w3schools because their quality control is sometimes less than stellar.

like image 162
Jim Garrison Avatar answered Sep 20 '22 11:09

Jim Garrison


https://css-tricks.com/attribute-selectors/

See |= section, the difference is in the dash separated list.

like image 34
seahorsepip Avatar answered Sep 20 '22 11:09

seahorsepip