Ver Mensaje Individual
  #5 (permalink)  
Antiguo 30/04/2013, 11:05
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 17 años, 8 meses
Puntos: 1567
Respuesta: Crear imagen con javascript?

Cita:
Iniciado por LeyVargas Ver Mensaje
Me gustaria saber emprear si es posible al tiempo de crear la imagen darle un id porque quiero modificar su tamaño en esa misma funcion y cambiarla de posición, saludos
Si, y no solo un id, fijate

Código HTML:
<!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>titulo</title> 
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<style type="text/css">
/*<![CDATA[*/
#img_uno{
width: 100px;
height: 100px;
}
.logo{
border: solid 3px #000;
}
/*]]>*/
</style>
<script type="text/javascript">
//<![CDATA[
function imagendiv() {
               var imagen = document.createElement("img"); 
               // agregamos propiedades al elemento
               imagen.src = "botones_enc.jpg"; 
               imagen.id = "img_uno";
               imagen.className = "logo";
               imagen.title = "titulo de la imagen";
               imagen.alt = "texto alternativo";
               imagen.onclick = function(){
              alert('el id de este elemento es: ' + this.id);
              };
               // definimos el elemento donde insertamos la imagen
               var div = document.getElementById("capa"); 
               // agregamos la imagen
               div.appendChild(imagen); 
           }
//]]>
</script>
</head>
<body>
<button onclick="imagendiv()">cccc</button>
<div id="capa"></div>
</body>
</html> 

el tamaño lo toma del id en el css y el borde de la clase, también le agregué un evento onclick

Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.