Ver Mensaje Individual
  #10 (permalink)  
Antiguo 20/04/2012, 08:49
Avatar de Melecio
Melecio
 
Fecha de Ingreso: julio-2011
Ubicación: Coahuila
Mensajes: 320
Antigüedad: 12 años, 10 meses
Puntos: 8
Respuesta: agregar y quitar archivos estilos css

Les agradesco a todos su ayuda asi quedo el ejemplo

<!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>
<title>Cambiar Estilos</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript">

function AGREGARYQUITARCSS(CSS) {
var e = document.getElementById(CSS);
if (e == undefined) {
//--cargar css
var CARGAR = document.createElement('link');
CARGAR.rel = 'stylesheet'
CARGAR.type = 'text/css';
CARGAR.href = CSS + '.css';
CARGAR.id = CSS;

document.getElementsByTagName('head')[0].appendChild(CARGAR);
//--cargar css
}else{

//---ELIMINAR CSS
var ESTILOCSS = document.getElementsByTagName('link')
for (var i=ESTILOCSS.length; i>=0; i--){
if (ESTILOCSS[i] && ESTILOCSS[i].getAttribute('href')!=null && ESTILOCSS[i].getAttribute('href').indexOf(CSS+'.css')!=-1)
ESTILOCSS[i].parentNode.removeChild(ESTILOCSS[i])
}
//---ELIMINAR CSS

}
}


</script>


</head>
<body>
<h1 class="original">Hola</h1>

<button onclick="AGREGARYQUITARCSS('original');">Agregar estilo original.css</button>

<button onclick="AGREGARYQUITARCSS('verde');">Agregar estilo verde.css</button>


</body>
</html>


muchas gracias.