Ver Mensaje Individual
  #12 (permalink)  
Antiguo 25/04/2010, 21:04
Avatar de Panino5001
Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Respuesta: Llamar archivo CSS desde Javascript

Una manera de hacerlo sería esta:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<
title>Documento sin título</title>
<
style>
#algo{background:#F00; font-size:16px; border:1px solid black;padding:5px}
</style>
<
script>
function 
addCss(cssCode,i) {
    
control=document.getElementById(i)
    if(
control)
        
document.getElementsByTagName("head")[0].removeChild(control)
    var 
styleElement document.createElement("style");
    
styleElement.type "text/css";
    if (
styleElement.styleSheet) {
        
styleElement.styleSheet.cssText cssCode;
    } else {
        
styleElement.appendChild(document.createTextNode(cssCode))
    }
    
styleElement.id =i;
    
document.getElementsByTagName("head")[0].appendChild(styleElement);

function 
cambiarA(selector,obj) {
  var 
miRegla document.styleSheets[0].rules || document.styleSheets[0].cssRules
  
for (var i=0reg=miRegla[i]; i++){
    if (
reg.selectorText.toLowerCase() == selector.toLowerCase() ){
        var 
paresreg.cssText || reg.style.cssText;
        
pares=pares.split('{').join('').split('}').join('').replace(reg.selectorText,'');
        var 
nombreclase='algo'+new Date().getTime();
        
addCss('.'+nombreclase+'{'+pares+'}','uuu');
        
obj.className=nombreclase;
    }
  }
}
</script>

</head>

<body>
<div onclick="cambiarA('#algo',this)">test </div>
</body>
</html>