Step 1: basic HTML page
The initial code
Here is the code that we will start with:
Let's go through the most relevant parts to understand what it does.
0.1 — The Doctype
The Doctype informs the browser which version of HTML is used in the file.
0.2 — The head
The <head>
tag can contain:
information about the page, such as the title
references to resources that need to be requested before creating the actual page content
inline scripts and styles
We are including Bootstrap's CSS file. Bootstrap is a UI framework that provides a set of predefined styles, components and scripts.
0.3 — The body
The body is the root of our application's visible content.
The element <div id="posts">
is where we will put all the messages. It is empty because the messages will be created dynamically using Javascript!
The posts container is wrapped by <div class="container">
. This div acts as a container for other elements that we will add in the future, and helps to better style and position its content. container
is a class used by Bootstrap.
0.4 — The script that creates a post
In order to create the first post, we split the code in two parts:
A generic
drawElement
function that appends some HTML to the posts container, customised with the provided message detailsA call to the
drawElement
function with the actual message data
0.4.1 — The drawElement
function
What is the function actually doing?
The first line of drawElement
gets the reference to the posts container.
The second part does a couple of things:
It concatenates a set of strings, some of which (title and body) are properties of the
post
input parameterIt appends the concatenated string to the post container as HTML
0.4.2 — The initialisation code
In order to create the message, we call the drawElement
function and pass the message data as parameter.
The message data is a Javascript object. It contains two properties, title
and body
.
The second line contains the call to the drawElement
function!
Last updated