title | verbose |
---|---|
Hello World |
true |
"Hello world" is a simple web application.
Let's see how it can be written in modernlit
,
the new literate programming environment for the web.
We'll start with the HTML file:
<html>
<!-- <<HTML head section>> -->
<body>
<span id="hello">Hello, world.</span>
</body>
</html>
The HTML head section in the code above indicates that we will fill this in later. Click on the link to visit the place in the document where it's defined.
The >
in >index.html
indicates that this is a file to be written out.
For this toy application, our CSS simply styles the "Hello, world" text, using its ID:
#hello {
color: purple;
}
We want to handle a click on the "Hello, World" text.
To do that, we set up an event listener with addEventListener
.
document.getElementById("hello").addEventListener("click", () => alert("clicked"));
Finally, let us come back to the head section of the HTML file.
<head>
<script src="./index.js"></script>
<link rel="stylesheet" href="./index.css">
</head>
The actual JS we include in this page needs to be wrapped in an event listener to be invoked when the DOM has loaded:
document.addEventListener("DOMContentLoaded", function(event) {
// <<Define handler for click on text>>
});
Here's a summary of all the fragments making up the app, and a picture of how they interrelate.
Each module points to other modules which it uses.
[[GRAPH]]
[[LOF]]