I am wondering how I can read CSS comments out of a linked stylesheet.
I have this sample CSS loaded via:
<link rel='stylesheet' type='text/css' media='all' href='test.css' />
#test1{ border:1px solid #000; } #test2{ border:1px solid #000; } #test3{/* sample comment text I'm trying to read */}
I’m testing this in FF3. The following javascript reads the rules but doesn’t read the comments in#test3.
window.onload = function(){ s=document.styleSheets; for(i=0;i < s[0].cssRules.length;i++){ alert(s[0].cssRules[i].cssText); } }
You could retrieve the stylesheet’s contents and use regex to parse the comments. This example uses jQuery to get the stylesheet text and a regular expression to find the comments:
You could also find the stylesheet links using selectors.