Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
JavaScript (Alert Message)

I have written a JavaScript alert message code it displays the alert message first in both codes 1 and 2 before Html content. What should I do to run the HTML content first and then a javascript code?

Code 1

<!DOCTYPE html>
<html>
    <head>
        <title>Hello, World !</title>

    </head>
    <body>
        <h1>I am learning JavaScript.</h1>
        <div id="Content">
            <p>This is a paragraph tag. Here the content of html.</p>
        </div>
        <script src="text.js"></script>
    </body>
</html>

Code 2

<!DOCTYPE html>
<html>
    <head>
        <title>Hello, World !</title>
    </head>
    <body>
        <h1>I am learning JavaScript.</h1>
        <div id="Content">
            <p>This is a paragraph tag. Here the content of html.</p>
        </div>
        <script>
alert(" This is alert message.");
</script>
    </body>
</html>
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

There is a load event, which will fire AFTER the page is loaded. You can listen to the event:

window.addEventListener('load', function() {
    console.log('All assets are loaded');
    alert ("This is an alert MSG");
})
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use setTimeout() for this

<html>
    <head>
        <title>Hello, World !</title>
        </head>
        <body>

          <h1>I am learning JavaScript.</h1>

          <div id="Content">
             <p>This is a paragraph tag. Here the content of html.</p>
          </div>

        <script>
         setTimeout(()=>{
           alert(" This is alert message.")     
          },2000)

        </script>
      
      </body>
  
   </html>
about 4 years ago · Juan Pablo Isaza Denunciar

0

In your first code just put defer attribute as below

<script defer src="text.js"></script>

A script that will be downloaded in parallel to parsing the page, and executed after the page has finished parsing

for more detail refer to the URL

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda