DOM Programming

From Elvanör's Technical Wiki
Revision as of 18:58, 25 February 2008 by Elvanor (talk | contribs) (New page: == StyleSheets == * The W3C specification allows for dynamic modification of CSS stylesheet. Firefox supports this, and IE too with proprietary, non standard APIs (not in Prototype, unfor...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

StyleSheets

  • The W3C specification allows for dynamic modification of CSS stylesheet. Firefox supports this, and IE too with proprietary, non standard APIs (not in Prototype, unfortunately). The main idea is to do something like:
document.styleSheets[0].insertRule(myCSSRule, 0);
  • In Firefox, there are several bugs. First you should only use insertRule() and removeRule. You can access the CSS <style> element directly and call update() on it, but that won't work a lot of times. Second, even when using the APIs, after an Ajax call it seems that delaying actions on the stylesheet is necessary, else some updates don't work (particularly on the background-image CSS property). You can use the delay() function of Prototype to achieve that.
  • It also seems impossible to access the object document.styleSheets[0].cssRules in Firefox 2. I got access violations.