var selector_css;
var sheet= document.styleSheets[0];
var rules= 'cssRules' in sheet? sheet.cssRules : sheet.rules;
for (var i= 0; i<rules.length; i++)
{
var rule= rules[i];
var text= 'cssText' in rule? rule.cssText : rule.selectorText+' {'+rule.style.cssText+'}';
text = text.replace(/\s/g, '');
selector_css = text.match(/^(.*?){/gi);
// selector_css = selector_css.replace(/{/g,''); // <- dont work ?
$('body').append('- '+selector_css+' <br />');
}
Everything works fine but when i add
sel开发者_StackOverflow中文版ector_css = selector_css.replace(/{/g,'');
I dont get a result or an error, but why? Can somebody help me?
http://jsfiddle.net/beMKY/
Thanks in advance!
PeterSome special chars like "." need to be escaped:
selector_css = selector_css.replace(/\{/g,'');
But in this case the problem is that css_selector is a object (array) and not a string.
You can apply replace
only to a string!!! Use
selector_css = selector_css[0].replace(/\{/g,'');
精彩评论