Estoy intentando un ejemplo muy básico de crear un div
dentro de un div
ya existente.Creando un elemento div dentro de un elemento div en javascript
no parece estar funcionando cuando uso:
document.getElementbyId('lc').appendChild(element)
pero funciona bien cuando hago esto:
document.body.appendChild(element)
¿Es necesario añadir windows.onload
función? ¡Aunque no funciona incluso entonces!
HTML:
<body>
<input id="filter" type="text" placeholder="Enter your filter text here.." onkeyup = "test()" />
<div id="lc">
</div>
</body>
JS código:
function test()
{
var element = document.createElement("div");
element.appendChild(document.createTextNode('The man who mistook his wife for a hat'));
document.getElementbyId('lc').appendChild(element);
//document.body.appendChild(element);
}
Es posible que desee probar firebug: hace que sea un poco más fácil detectar errores tipográficos en su código. –