Ver Mensaje Individual
  #4 (permalink)  
Antiguo 07/02/2011, 09:10
Avatar de _cronos2
_cronos2
Colaborador
 
Fecha de Ingreso: junio-2010
Mensajes: 2.062
Antigüedad: 13 años, 10 meses
Puntos: 310
Respuesta: Misterio de la lectura CSS

JavierB tiene unas funciones para eso, yo las recopilé todas en un objeto, mira a ver si te sirve:
Código Javascript:
Ver original
  1. String.prototype.low=function(){ return this.toLowerCase(); };
  2. var extSS = function(){};
  3. extSS.prototype = {
  4.  isIE : document.all,
  5.  instrucciones : {
  6.   'reglas' : this.isIE ? 'rules' : 'cssRules',
  7.   'add' : (this.isIE ? 'add' : 'insert') + 'Rule',
  8.   'remove' : (this.isIE ? 'remove' : 'delete') + 'Rule'
  9.  },
  10.  hojas : document.styleSheets,
  11.  getSS : function(id){
  12.   var cosa;
  13.   switch(typeof id){
  14.    case 'number' :
  15.     return this.hojas[id] ? this.hojas[id] : false;
  16.    break;
  17.    case 'string' :
  18.     for(var url = /(file|http):\/\/(\/*).+\//, i=0; cosa = this.hojas[i]; i++){
  19.      if(cosa.href == id || cosa.href.replace(url, '') == id || cosa.href.replace(url, '').replace(/\.css$/, '') == id)
  20.       return cosa;
  21.     }
  22.    break;
  23.   }
  24.   return false;
  25.  },
  26.  find : function(select, propi){
  27.   var estilo;
  28.   for(i=0; sheet = this.hojas[i]; i++){  
  29.    estilo = sheet[this.instrucciones['reglas']];
  30.    for(j=0; regla = estilo[j]; j++){
  31.     if(regla.selectorText.low() == select.low() && regla.style[propi])
  32.      return regla.style[propi];
  33.    }
  34.   }
  35.   return false;
  36.  },
  37.  set : function(select, propi, val){
  38.   var estilo;
  39.   for(i=0; sheet = this.hojas[i]; i++){  
  40.    estilo = sheet[this.instrucciones['reglas']];
  41.    for(j=0; regla = estilo[j]; j++){
  42.     if(regla.selectorText.low() == select.low() && regla.style[propi])
  43.      regla.style[propi] = val;
  44.    }
  45.   }
  46.   return false;
  47.  },
  48.  add : function(hoja, select, propi, val){
  49.   var SS = this.getSS(hoja);
  50.   try{
  51.    SS.insertRule(select + '{' + propi + ':' + val + '}', SS[this.instrucciones['reglas']].length);
  52.   }catch(e){ // IE
  53.    SS.addRule(select, propi + ':' + val);
  54.   }
  55.  },
  56.  remove : function(hoja, select){
  57.   var estilo;
  58.   switch(typeof hoja){
  59.    case 'number' :
  60.     estilo = this.hojas[hoja][this.instrucciones['reglas']];
  61.     for(i=0; regla = estilo[i]; i++){
  62.      if(regla.selectorText.low() == select.low())
  63.       this.getSS(hoja)[this.instrucciones['remove']](j);
  64.     }
  65.    break;  
  66.    case 'string' :
  67.     if(hoja=='all'){
  68.      for(i=0; sheet = this.hojas[i]; i++){
  69.       estilo = sheet[this.instrucciones['reglas']];
  70.       for(j=0; regla = estilo[j]; j++){
  71.        if(regla.selectorText.low() == select.low())
  72.         sheet[this.instrucciones['remove']](j);
  73.       }
  74.      }
  75.     }else{
  76.      var SS = this.getSS(hoja), estilo = SS[this.instrucciones['reglas']];
  77.      for(i = 0; regla = estilo[i]; i++){
  78.       if(regla.selectorText.low() == select.low())
  79.        SS[this.instrucciones['remove']](i)
  80.      }
  81.     }
  82.    break;
  83.   }
  84.  }
  85. };
  86. var SS = new extSS();
Esto busca por las StyleSheets del documento, así que no te servirá para saber por ejemplo el tamaño de fuente de un párrafo sin ningún estilo (para se usa getComputedStyle() creo), pero si lo tienes definido en algún sitio sí.
Saludos (:
__________________
" Getting older’s not been on my plans
but it’s never late, it’s never late enough for me to stay. "
Cigarettes - Russian Red