Script
<html>
<body>
<script>
/**
* Javascript code can be inserted almost anywhere into a HTML
* 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.
*/
alert('Hello, world!'); // alert in browser
console.log('Hello, world'); // message in console
</script>
</body>
</html>
File
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js">
/**
* If we have a lot of code, we can put it into a file.
* 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>
Last update: 183 days ago