Cita:
Iniciado por LeyVargas
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