Hi everyone, I'm having an issue that's doing my head in and I kind of need some quick assistance. Anyone that can help me solve this I will pay $50 into your PAYPAL account! Basically I have this: <STYLE> .at_ { width:325px; background-color: none; padding: 3px; } .at2 { padding-bottom: 1px; padding-top: 4px; padding-left: 3px; padding-right: 3px; vertical-align:top; text-align:left; } </STYLE> I have some javascript just under it where I need to basically get those styles, put them into a variable. <SCRIPT> var styles =""; </SCRIPT> I have done a fair bit of looking around but can't seem to find a method that will allow me to do this, but it must be possible! Any help appreciated... there's $50 in it for the person that either gives me a solution or at least assists finding one!
Please PM with with your exact requirements. I can extract the styles from the <style> and </style> but do you need just all the styles in a single string or you want some breakup too?
Hi Ruby, you can see the script's working snapshot here. http://i219.photobucket.com/albums/cc14/RohanShenoyThane/ruby.gif You will be able to extract all style statements into a string or even break them up w.r.t CSS selectors.
I just require all the styles in a single string... the styles could be different to and there could be more
Here is something to get you started: function dumpStyleSheet(n){ var ie = !!window.ActiveXObject, styles = ""; if (!ie){ var i = 0, rules = document.styleSheets[n].cssRules, l = rules.length; for ( ; i < l; i++) styles += rules[i].cssText; } else styles = document.styleSheets[n].cssText; return styles; } PHP: This will dump all the contents of the chosen style sheet - n - and return them for you. The first argument is which stylesheet to dump as a page can have an unlimited number of stylesheets. Counting starts at 0. So to get the text in the first stylesheet you would say dumpStyleSheet(0), to get it from the second you would say dumpStyleSheet(1), and so on. So to do what you want in your first post just do this: var styles = dumpStyleSheet(0); PHP: The function should work in any modern browser.