In order to understand how you can change the content of an HTML page using JavaScript, you need to know how a browser interprets the HTML code and applies styling to it.
- RECEIVE A PAGE AS HTML CODE
- CREATE A MODEL OF THE PAGE AND STORE IT IN MEMORY
- USE A RENDERING ENGINE TO SHOW THE PAGE ON SCREEN
Web developers usually talk about three languages that are used to create web pages: HTML, CSS, and JavaScript. Where possible, aim to keep the three languages in separate files,with the HTML page linking to CSS and JavaScript files. Each language forms a separate layer with a different purpose. Each layer, from left to right. builds on the previous one.
** CONTENT LAYER . html files** ** {css} PRESENTATION LAYER . css file** ** javascri pt() BEHAVIOR LAYER .js files **
It is best to keep JavaScript code in its own JavaScript file. JavaScript files are text files (like HTML pages and CSS style sheets), but they have the . j s extension. The HTML <script> element is used in HTML pages to tell the browser to load the JavaScript file (rather like the element can be used to load a CSS file). If you view the source code of the page in the browser, the JavaScript will not have changed the HTML,because the script works with the model of the webpage that the browser has created.
A script is a series of instructions that a computer can follow one-by-one. Each individual instruction or step is known as a statement. Statements should end with a semicolon.