On 16/03/2007, at 10:01 AM, Danny Wachsstock wrote:
> function styleString(selector){
> var style = "";
> $.each (document.styleSheets, function(){
> $.each (this.cssRules || this.rules, function() {
> if (this.selectorText == selector) style +=
> this.style.cssText + ';';
> });
> });
> return style;
> }
Haha, that's funny. I was just about to post my rewrite and the code
is very similar to yours except yours is better due to the use of ||
instead of my ternary, plus I used a regexp as per the original which
from your code looks like it's not needed. Mine's untested too. Here
it is for giggles:
$.getClassContent = function(classname) {
var cssText = '';
$.each(document.styleSheets,function() {
var cssRules = (typeof this.cssRules == 'array') ?
this.cssRules :
this.rules;
$.each(cssRules,function() {
if ('/\.'+classname+'/'.test(this.selectorText)){
cssText = this.style.cssText;
}
});
});
return cssText;
};
Joel.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/