< JavaScript Programming < Introduction

example.html

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 
 4 <head>
 5   <meta charset="UTF-8">
 6   <meta http-equiv="Cache-Control" content="no-cache">
 7   <title>Example</title>
 8   
 9   <!-- The following line loads the external script. -->
10   <script src="example.js" async></script>
11 
12   <script>
13     //script in head
14     document.write("Hello Wikiversity!");
15   </script>
16 </head>
17 
18 <body>
19   <noscript>Enable JavaScript to see web page content.</noscript>
20   <p id="text"></p>
21   <p id="html"></p>
22   
23   <script>
24     //script in body
25     window.alert("Hello Wikiversity!");
26   </script>
27 </body>
28 
29 </html>

example.js

1 //This script demonstrates JavaScript output five different ways.
2 //Two script blocks are in the HTML page. This script is external.
3 
4 document.getElementById("text").innerText = "Hello Wikiversity!";
5 document.getElementById("html").innerHTML = "<strong>Hello Wikiversity!</strong>";
6 console.log("Hello Wikiversity!")
This article is issued from Wikiversity. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.