Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda