Good! I chatted with Joseph Marikle and we worked on a lot of examples trying to track down the problem.
I have good news and I have bad news. Bad news first β I donβt know exactly what the hell is going on. Good news? I have a job!
So, firstly, if your element is on the page at design time (not dynamically generated), then while the element attribute exists, css should work.
eg:.
<!DOCTYPE html> <html> <head> <title>Example</title> <style> a:after { content: attr(title); } </style> </head> <body> <a id="targetElement" title="hi" href="http://www.google.com">Hello World</a> <script type="text/javascript"> document.getElementById("targetElement").setAttribute("title", " moo"); </script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/knockout/knockout-2.2.1.js"></script> </body> </html>
This example works because targetElement has a title attribute. The title is moo at runtime, and css reflects this, showing the content as "moo".
If you remove the code header = "hi", you will not see moo. FURTHERMORE, if targetElement is not on the page when you start css - you will not see moo - even if you create targetElement with an existing title attribute.
If you want to dynamically generate your elements and work with this css, I have a second workaround and I use this method. The problem is that IE8 does not find this element when it applies the pseudo selector and it does not restart its logic when the element appears.
So, if you are something like ..
node.children('a').attr('data-content', '[' + usedRackUnits + '/' + rackTooltipInfo.rackModel.rows + ']'); var addRule = function (sheet, selector, styles) { if (sheet.insertRule) return sheet.insertRule(selector + " {" + styles + "}", sheet.cssRules.length); if (sheet.addRule) return sheet.addRule(selector, styles); }; addRule(document.styleSheets[0], 'li[rel="rack"] > a:after', "content: attr(data-content)");
This will change your stylesheet at runtime and add a new CSS rule. This forces IE8 to reapply the logic, and since the dynamic elements are on the page now, it finds them and applies css accordingly. Woohoo! Stupid IE8.