Example 1
Code: Select all
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Embedding JavaScript</title>
</head>
<body>
<div id="greet"></div>
<script>
document.getElementById("greet").innerHTML = "Hello World!";
</script>
</body>
</html>
Example 2
Code: Select all
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>External JavaScript Example</title>
</head>
<body>
<script type="text/javascript" src="/hello.js"></script>
</body>
</html>
Example 3
Code: Select all
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>No-script Example</title>
</head>
<body>
<script type="text/javascript">
document.write("Hello World!");
</script>
<noscript>
<p>Sorry, your browser does not support JavaScript!</p>
</noscript>
</body>
</html>