HTML elements and their tags, attributes, and their values, are they building blocks of web pages. Structured documents with style sheets can be viewed on a wide variety of devices. HTML elements also assist computer agents such as search engines in making more sense of a page. - http://www.w3.org/standards/webdesign/htmlcss
Answer: opening tag, closing tag, element content, attribute(s)
Cascading Style Sheets (CSS) is a simple mechanism for adding style (e.g., fonts, colors, spacing) to Web documents.
- http://www.w3.org/Style/CSS/Overview.en.html
Answer: selector, declaration block, property:value pairs
Answer: Selectors are a syntax for pattern matching and are used to "select" elements on the page that we want to style. The three most common selectors are:
p{color:red;}
.myclass{color:red;}
#weatherDiv{color:red;}
Answer: universal selector, attribute selector, descendant combinator - see http://www.w3.org/TR/css3-selectors/#selectors for a full list.
Answer: When a <script>
is encountered by the browser's parser, the code is passed off to the JavaScript interpreter and executed.
<script>
element is commonly placed in the <head>
section of the document.<script>
element at the end the <body>
tag.<script>
element can also be placed in a separate file and linked to with a <script>
tag. This is the preferred method if you have more than a trivial amount of JavaScript code on a page."use strict"
do?Answer: read here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode
window.onload = init;
Answer: It calls the init
function once the window.onload
event has fired. window.onload
must point a reference to a function (i.e. the name of a function). Note: the name of the event is case sensitive, it's onload
, NOT onLoad
console.log()
Answer: The results appear in the JavaScript console.
Chrome comes pre-installed with Developer Tools (a "web inspector") which you can view by right-clicking in the browser window and choosing "Inspect Element". Clicking on the console tab reveals the console log - which is handy for simple debugging.
OS X users have a Safari Web Inspector that is nearly identical to Chrome's and also invoked by right-clicking. Be aware you will have to first enable it, by checking "Show Develop in Menu Bar", which is located under Safari > Preferences... - the Advanced tab.
init
like this window.onload = init();
often causes the code to fail. Where can we see the error message? Why will the code usually fail?Answer:
()
to the end of the function it is instead called immediately, and whatever value the function returns is what is stored in the event handler. In the case above, window.onload
would now point at Null
undefined
()
are also known as the invocation operator or the function call operator. Placing them after a function name causes the function to be called immediately.window.onload = init;
?Answer: jQuery's $.ready()
function, or a JS event listener. Here's an example of an event listener: window.addEventListener("load", init)
- note that in event listeners we use just the name of the event without the "on"(i.e. event listeners expect "load" or "click", not "onload" or "onclick" as the first argument)