Rúben Periquito Developer 3 Posted March 20, 2020 Report Share Posted March 20, 2020 <!DOCTYPE html> <html> <head> <title></title> </script> </head> <body> <h1>Title News</h1> <h2>These are today's news</h2> <div id="news1">Today's news are nothing special. Please come back tomorrow...</div> <script type="text/javascript"> var firstelement = document.getElementById("news1"); alert(firstelement); </body> </html> Rúben Periquito Link to post Share on other sites
Zex 8 Posted March 20, 2020 Report Share Posted March 20, 2020 O " </script> " está em cima em vez de estar depois do "alert" Link to post Share on other sites
Rúben Periquito Developer 3 Posted March 20, 2020 Author Report Share Posted March 20, 2020 1 hora atrás, Zex disse: O " </script> " está em cima em vez de estar depois do "alert" e aqui? <!DOCTYPE html> <html> <head> <title></title> </head> <body> <h1>Title News</h1> <h2>These are today's news</h2> <div id="news1">Today's news are nothing special. Please come back tomorrow...</div> <script type="text/javascript"> var parent = document.childNodes[0].childNodes[0]; alert(parent.nodeName); </script> </body> </html> porque não aparece um alerta de Javascript com o nome do "filho"? Rúben Periquito Link to post Share on other sites
M6 149 Posted March 21, 2020 Report Share Posted March 21, 2020 A página é enviada ao browser e só quando este a recebe toda é que a começa a interpretar. Só depois de estar estar pronta é que o Javascript é executado, tem a ver com o ciclo de vida do DOM. Podes ler mais aqui: http://tilomitra.com/html-page-lifecycle-events/ http://tilomitra.com/html-page-lifecycle-events/ https://www.thoughtco.com/javascript-execution-order-2037518 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to post Share on other sites
Zex 8 Posted March 21, 2020 Report Share Posted March 21, 2020 o javascript funciona em qualquer lado <!DOCTYPE html> <html> <head> <title></title> <script> var parent = document.childNodes[0]; alert(parent.nodeName+1); </script> <script type="text/javascript"> function run() { var parent = document.childNodes[0]; alert(parent.nodeName+2); } </script> </head> <body onload="run()"> <h1>Title News</h1> <h2>These are today's news</h2> <div id="news1">Today's news are nothing special. Please come back tomorrow...</div> <script> var parent = document.childNodes[0]; alert(parent.nodeName+3); </script> </body> <script> var parent = document.childNodes[0]; alert(parent.nodeName+4); </script> </html> <script> var parent = document.childNodes[0]; alert(parent.nodeName+5); </script> Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now