0

I want my JavaScript to load after page is loaded but now it iss loading before the the page is loaded.

How can I fix it.

<body>
    <h1>My Website</h1>
    <div class="container">
        <div class="jumbotron"">
            <h1>Let's Learn Javascript</h1>
            <p class="lead">...cause Javascript ROCKS.</p>
        </div>
    </div>
    <script src="scripts/main.js"></script>
    <script src="scripts/arrays.js"></script>
    <script src="scripts/loops.js"></script>
 </body>
J M
  • 396
  • 6
  • 23

3 Answers3

0

You can use defer keyword to load javascript async after full page loads

<body>
    <h1>My Website</h1>
    <div class="container">
        <div class="jumbotron"">
            <h1>Let's Learn Javascript</h1>
            <p class="lead">...cause Javascript ROCKS.</p>
        </div>
    </div>
    <script src="scripts/main.js" defer></script>
    <script src="scripts/arrays.js" defer></script>
    <script src="scripts/loops.js" defer></script>
 </body>
0

You can add a onload attribute to your code inside the body.

<body onload="script();">
0

I would advise you use "script defer" since your scripts are external. For more information and understanding, kindly follow this link: HTML Attribute - Script Defer

Benneee_
  • 319
  • 1
  • 7