On 2/16/06, Nicolas Terray <[EMAIL PROTECTED]> wrote: > Hi all, > > I have a property, defined in an external stylesheet: > > .my_class { > background-color: #FF0000; > } > > > I want to retrieve the value of this background-color of the class my_class. > > How can I do that with prototype/scriptaculous ? > > Thanks in advance, > Nicolas Terray >
I've just found this script: ---8<--------- function getStyleClass (className) { var re = new RegExp("\\." + className + "$", "gi"); if (document.all) { for (var s = 0; s < document.styleSheets.length; s++) for (var r = 0; r < document.styleSheets[s].rules.length; r++) if (document.styleSheets[s].rules[r].selectorText.search(re) != -1) { return document.styleSheets[s].rules[r].style; } } else if (document.getElementById) { for (var s = 0; s < document.styleSheets.length; s++) for (var r = 0; r < document.styleSheets[s].cssRules.length; r++) if (document.styleSheets[s].cssRules[r].selectorText.search (re) != -1) { document.styleSheets[s].cssRules[r].sheetIndex = s; document.styleSheets[s].cssRules[r].ruleIndex = s; return document.styleSheets[s].cssRules[r].style; } } else if (document.layers) return document.classes[className].all; return null; } function getStyleClassProperty (className, propertyName) { var styleClass = getStyleClass(className); if (styleClass) return styleClass[propertyName]; else return null; } ---8<--------- http://www.faqts.com/knowledge_base/view.phtml/aid/1939/fid/255 It works pretty find on Fx 1.0.7 and IE6 however I don't understand all in this script. What does those lines mean : document.styleSheets[s].cssRules[r].sheetIndex = s; document.styleSheets[s].cssRules[r].ruleIndex = s; ??? As javascript experts, could you tell me if this script is correct, not too old and unoptimizable ? Anyways, other suggestions are welcome! Thanks, Nicolas Terray _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs