My version (more jQuery-ish). It uses a very simple test for the selector
(this.selectorText == selector) but you could use a fancier RegExp-based
version if you wanted. It works in FF and IE. It does not deal with
differing media and @import rules.
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;
}
But how are you going to use this if MySpace won't allow javascript?
Danny
Javier Infante wrote:
>
> El jue, 15-03-2007 a las 18:50 +0000, [EMAIL PROTECTED]
> escribió:
>> Thanks but what I am really trying to do is find out all the attributes
>> that define "myClass". Below it appears you have hard-coded certain
>> values, but I won't know those ahead of time and there could be different
>> classes per element, each defined differently.
>>
>> Thanks, - Dave
>
> Hi Dave,
>
> I have found your question interesting and i think i have got you a
> point from where you can start.
>
> Alltought the code is not jquery at all maybe some jquery hacker finds
> it interesenting to develop a small plugin (if i get some time i might
> give it a try)
>
> here goes the code:
>
> function getClassContent(classname) {
> for (var i=0; i<document.styleSheets.length; i++) {
> var styleSheet=document.styleSheets[i];
> var ii=0;
> var cssRule=false;
> do {
> if (styleSheet.cssRules) cssRule =
> styleSheet.cssRules[ii];
> else cssRule = styleSheet.rules[ii];
> if (cssRule) {
> eval ("regExp = /\."+classname+"/"); // I will
> look for
> div".classname" in the css
> if (regExp.test(cssRule.selectorText))
> return cssRule.style.cssText;
> }
> ii++;
> } while (cssRule);
> }
> }
>
> alert(getStyleAttribute("infoExtra"));
>
> This thing will only work with css rules defined as class (div.myClass),
> but not with css rules defined for id (div#myId)... allthought i think
> you could make that work not to hardly.
>
> anyway, is this what you were looking for?
>
>
> --
> Javier Infante
> Dpto. Internet y Desarrollo
> Irontec, Internet y sistemas sobre GNU/Linux - http://www.irontec.com
> +34 94 404 81 82 - Ext. 202
>
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
>
--
View this message in context:
http://www.nabble.com/How-to-convert-%22class%22-to-%22style%3D%27attrs-...%27%22-tf3409582.html#a9505455
Sent from the JQuery mailing list archive at Nabble.com.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/