2
I’m starting at the javascript
and wanted to create html elements dynamically but when you load the page it goes blank and does not add the elements
code below:
function add (){
var texto = document.createTextNode("teste");
var p = document.createElement("p");
var ptexto = p.appendChild(texto);
var body = document.getElementsByTagName("body")[0];
body.appendChild(ptexto);
}
thanks everyone, I tried to run in the browser but it did not appear, and it appears a msg the time I inspect the page appears Uncaught Typeerror: Cannot read Property 'appendchild' of Undefined would be something of configuration?
– Marcelos Dourado
Sergio and I think you want to remember, I see that beautiful Song, https://www.youtube.com/watch?v=Rr7TaaJ60Ws
– user60252
@Leocaracciolo :)
– Sergio
@Markup This appears if you are adding Javascript inside the
head
. Place at the end ofbody
or withwindow.load = function(){ /* o código aqui */ }
– Sergio
@Marceosdourado Asssim:
[seu html] ... <script src="..."></script></body></html>
– bfavaretto