Chapter 1c - How do I write a script for a web page? Flashcards
How HTML CSS and JavaScript fit together
Different languages should be kept in separate files
HTML is…
The content layer
It is where the content of the page lives
It adds page structure and semantics
CSS is…
The presentation layer
CSS enhances HTML with rules that state how HTML content is presented
JavaScript is…
The behaviour layer
This is where we can change how a web page behaves.
It adds interactivity
We should keep as much of our JavaScript in separate files as possible
Progressive Enhancement is
Many aspects of a browsing experience differ
screen size
connection speed
device capability
HTML first
works on all devices
HTML and CSS
separate rules for how the page looks
One fast sheet, or many to create different views of the same data
HTML, CSS and JavaScript
JS added last
Enhances usability / interactivity of the site
Keeping it separate means the site works without JS
JS code can be reused on several pages
Javascript is written in…
Plain text with a .js file suffix
Javascript is added to a page…
using the HTML element - this tells the browser it has encountered a script
The script element has a src attribute, the value of which is the path script that was created
Does Javascript alter the source code?
No. The script works with the DOM.
Is it possible to add Javascript directly to a page? Is it recommended?
It is possible, between tags. It is not recommended, as it is best to separate files.
Describe how object and methods work, using an example
Example - document.write(‘Good afternoon!’);
The document object represent the entire web page
The document has various methods and properties
These are called members of the object
The dot is the member operator.
It joins the object name to the member you want to access.
When a method needs information to work, the data is given within parentheses,
Each bit of information of this type is called a parameter
Above the write() method needs to know what to write
When will a browser execute JavaScript?
It will execute it when it finds it, stopping to load the script and then checking if anything needs doing.