I have set up a simple test page to illustrate the problem I have encountered.
Briefly, this works as expected (text is formatted in bold, underlined red):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style>
[abc=x1] {
color: red;
text-decoration: underline;
font-weight: bold;
}
</style>
</head>
<body>
<div abc=x1>hello</div>
</body>
</html>
And this does not (text stays black, no formatting applied):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style>
[abc=1] {
color: red;
text-decoration: underline;
font-weight: bold;
}
</style>
</head>
<body>
<div abc=1>hello</div>
</body>
</html>
The only thing I changed between the two examples is the attribute value (in both the CSS and HTML) from x1 to 1.
So it seems that you cannot match against numerical attributes.
Does anyone have any idea why this… very… useful… feature… exist?
Wrap the string to match in quotes…
jsFiddle.
Source.
When you wrap it in quotes, you are telling it to match a string.
When you don’t quote it, it is looking for an identifier.