Foros del Web » Programando para Internet » Javascript »

No anda setAttribute

Estas en el tema de No anda setAttribute en el foro de Javascript en Foros del Web. Hola, Estoy creando una funcion que me cambie el css: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código html: Ver original <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> < ...
  #1 (permalink)  
Antiguo 04/04/2009, 15:11
Avatar de pato12  
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 7 meses
Puntos: 101
No anda setAttribute

Hola,
Estoy creando una funcion que me cambie el css:
Código html:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  4. <title>Documento sin t&iacute;tulo</title>
  5. <script type="text/javascript">
  6. <!--
  7. function $(id){
  8.     return document.getElementById(id);
  9. }
  10. function $css(id,ob){
  11.     for (at in ob) {
  12.         if(at=="opacity"){
  13.             $(id).style.opacity=(ob[at]);
  14.             $(id).style.MozOpacity=(ob[at]);
  15.             $(id).style.KhtmlOpacity=(ob[at]);
  16.             $(id).style.filter="alpha(opacity="+ob[at]+")";
  17.         }else{
  18.             $(id).setAttribute(at,""+ob[at]);
  19.         }
  20.     }
  21. }
  22. -->
  23. </head>
  24.  
  25. <div style="height:500px; width:300px; background-color:#666666;" id="divT"></div>
  26. <input type="button" onclick="$css('divT',{opacity:'0.8',height:'50px',width:'50px'})" value="Probar" />
  27. </body>
  28. </html>
El opacity me cambia bien, pero el tamañono.
Gracias
Salu2
__________________
Half Music - www.halfmusic.com
  #2 (permalink)  
Antiguo 04/04/2009, 15:18
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: No anda setAttribute

Prueba así:
Código javascript:
Ver original
  1. $(id).style[at] = ob[at];
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #3 (permalink)  
Antiguo 04/04/2009, 15:24
Avatar de pato12  
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 7 meses
Puntos: 101
Respuesta: No anda setAttribute

Hola,
Muchas gracias!
Salu2
__________________
Half Music - www.halfmusic.com
  #4 (permalink)  
Antiguo 04/04/2009, 16:20
Avatar de pato12  
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 7 meses
Puntos: 101
Respuesta: No anda setAttribute

Y como puedo hacer para que si ob no es un objeto, me devuelva false.
Gracias
Salu2
__________________
Half Music - www.halfmusic.com
  #5 (permalink)  
Antiguo 04/04/2009, 16:31
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: No anda setAttribute

Puedes usar typeof:
https://developer.mozilla.org/es/Ref...eciales/typeof
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:45.