Rúben Periquito Developer Posted March 20, 2020 at 07:52 PM Report Share #617655 Posted March 20, 2020 at 07:52 PM <!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 comment Share on other sites More sharing options...
Zex Posted March 20, 2020 at 08:12 PM Report Share #617657 Posted March 20, 2020 at 08:12 PM O " </script> " está em cima em vez de estar depois do "alert" Link to comment Share on other sites More sharing options...
Rúben Periquito Developer Posted March 20, 2020 at 09:43 PM Author Report Share #617658 Posted March 20, 2020 at 09:43 PM 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 comment Share on other sites More sharing options...
M6 Posted March 21, 2020 at 11:42 AM Report Share #617663 Posted March 21, 2020 at 11:42 AM 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 comment Share on other sites More sharing options...
Zex Posted March 21, 2020 at 09:02 PM Report Share #617675 Posted March 21, 2020 at 09:02 PM 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 comment Share on other sites More sharing options...
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