I'm attempting to use attribute selectors and CSS for formatting elements.
The HTML looks like:
<div id="user" highlight="false">User Name</div>
The CSS is:
[highlight=true]
{
background-color: red;
}
[highlight=false]
{
background-color: white;
}
And then there's some accompanying JavaScript:
if( foo )
{
node.setAttribute('highlight', true);
}
else
{
node.setAttribute('highlight', false);
}
This works in Firefox and Chrome. When the highlight attribute gets changed by the JavaScript, the element's background color changes as appropriate. In IE8, however, it's a different story. The element will display correctly according to the highlight value that is initially assigned in the HTML, but when the attribute is changed dynamically the display of the element doesn't change.
Is this a known quirk, and is there a known work-around?
Update I just changed the attribute name to "frob" with values "on" and "off." That should settle any issue about reserved or interpretable values.
One other thing of note. When I turn on the IE8 developer tools and use the HTML inspector, it will show the style [frob=on] or [frob=off] as applied for whatever value frob had when I started the document inspector. However, the frob attribute will then no longer change in the inspector view. In no case do the values in the [frob=on/off] css ever get applied after the initial render of the HTML.
Update: Problem Solved The solution is to force a redraw. There are various ways of doing this, but it appears the standard one is to reassign the className to itself.