- The head section is used to put things not immediately shown on the page.
- The body section is used to put the things immediately shown on the webpage when loaded.
Well, in Javascript this is not always the case. In Javascript, code in the head section can be automatically activated. However, this is not always the case. For now, we will put Javascript in the body section to make it easier when learning. So, draw up a basic webpage that shows nothing, like such:
<html> <head> </head> <body> </body> </html>
Now, let me explain something:
document.write();
document.write() is a function of Javascript. In Javascript you have "objects", and "functions." To keep it simple now, "document" is the object, and "write()" is a function.
Spoiler
"Document" is the object, which represents the entire webpage. So, in other words, the webpage is a "document." Now, you can probably take a pretty good guess as to what write() is, but I shall tell you anyway. "write()" is a function that will "write" text onto the document, the webpage. Now, in order to tell document.write() what to type on the screen, you'll have to insert quoation marks inside the parentheses and type whatever you want inside of them. For this example, we'll use "Hello World." Try typing up the Javascript code that it will write "Hello World."
Completed Javascript code:
Spoiler
Now that you have that code, we don't know exactly where to put it. In Javascript ALL (so far) code goes inside script tags. For script tags, type the following:
<script type="text/javascript"></script>
As you may have noticed, the javascript script tags are very similiar to the style tags in CSS:
<style type="text/css">CSS</style>
Now that you know what script tags are, it's only logical that we put our Javascript in the script tags, and then insert that into the body sections, as planned. Please try to do that now.
The correct answer:
Spoiler
If you understand this, you can advance to Javascript 2 - Functions and Event Handlers.
~Taken from my Javascript blog.







MultiQuote





|