PROGRAMMING

  MINTE9
REMEMBERS




Last update:   13-05-2022

Script

Javascript code can be inserted almost anywhere into an HTML.
 
<!doctype html>
<html>
<body>
  <script>

    /**
     * The <script> tag is automatically executed 
     * when the browser processes the tag.
     * 
     * The old HTML standard required a script to have a type. 
     * It’s not required anymore.
     * 
     * Now, it can be used for JavaScript modules.
     */
    
    alert('Hello, world!'); // alert in browser

    console.log('Hello, world'); // message in console

  </script>
</body>
</html>

File

If we have a lot of code, we can put it into a file.
 
<!doctype html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js">
    /**
    * The browser will download it and store it in its cache.
    * Pages that reference the same script will take it from there.
    * This reduces traffic and pages are faster.
    */
</script>
</head>
<body>
    
    <p id='content'></p>

    <script>
        $('#content').text('Hello World');
    </script>

</body>
</html>

Questions     github Fundamentals
Code structure
        A B C D E F
🔔
1/3