Hola, en el siguiente programa me aparece la ventana de alert() pero me sale vacía en lugar de indicar el dato que le pido (height). ¿Alguien puede echarme un cable?
HTML:
Using html4strict Syntax Highlighting
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<link rel="stylesheet" href="estilo.css" type="text/css" media="screen"></link>
<script type="text/javascript" src="biblioteca.js"></script>
</head>
<body>
<div id="bloqcent">
<ul id="departamentos">
<li id="departienda">TIENDA</li>
<li id="deparreparaciones">REPARACIONES</li>
</ul>
<div id="cuerpo">cuerpo
<div id="tienda" name="hola"></div>
<div id="reparaciones"></div>
</div>
</div>
</body>
</html>
CSS:
Using html4strict Syntax Highlighting
#bloqcent{float:left;
width:70%;
}
#departamentos li{float:left;
width:20%;
height:25px;
text-align:center;
margin-right:1%;}
#cuerpo{clear:left;
border:1px solid black;
height:300px;}
#tienda{height:100px;background-color:orange;display:block;}
#reparaciones{height:100px;background-color:blue;display:block;}
JS:
Using javascript Syntax Highlighting
function cambiardepar()
{
var nombre=document.getElementById("tienda");
alert(nombre.style.height);
}
window.onload = function()
{
document.getElementById("departienda").onclick = cambiardepar;
document.getElementById("deparreparaciones").onclick =cambiardepar;
}
En este otro caso veo que me funciona la cosa utilizando getElementById() pero no usando getElementsByName(). ¿Qué estoy haciendo mal?
(El HTML y CSS son los mismos que los anteriores)
JS (sí funciona):
Using javascript Syntax Highlighting
function cambiardepar()
{
document.getElementById("tienda").style.display="none";
}
window.onload = function()
{
document.getElementById("departienda").onclick = cambiardepar;
document.getElementById("deparreparaciones").onclick =cambiardepar;
}
JS (no funciona):
Using javascript Syntax Highlighting
function cambiardepar()
{
document.getElementsByName("hola").style.display=" none";
}
window.onload = function()
{
document.getElementById("departienda").onclick = cambiardepar;
document.getElementById("deparreparaciones").onclick =cambiardepar;
}
A ver si alguien puede sacarme de dudas. Gracias.