From http://www.w3schools.com (Copyright Refsnes Data)

JavaScript Primer

Previous Next

An HTML file can contain text, HTML tags and scripts. Scripts in an HTML file can be executed by the browser.


What is JavaScript?

JavaScript is used in millions of Web pages to improve the design, validate forms, detect browsers, create cookies, and much more.

JavaScript is the most popular scripting language on the internet, and works in all major browsers.


Client-Side Scripting

JavaScript is about "programming" the behavior of the browser. This is called client-side scripting or browser scripting.

Server-side scripting is about "programming" the behavior of the server (see Web Scripting chapter).


What can a JavaScript Do?


How to Put a JavaScript Into an HTML Page

<html>
<body>
<script type="text/javascript">
document.write("Hello World!")
</script>
</body>
</html>

The code above will produce this output on an HTML page:

Hello World!

Example Explained

To insert a JavaScript into an HTML page, we use the <script> tag. The type attribute defines the scripting language.

So, the <script type="text/javascript"> tells where the JavaScript starts:

<script type="text/javascript">

The JavaScript command for writing some output to a page is document.write:

document.write("Hello World!")

Then, the script ends:

</script>


Try-It-Yourself Examples

Write text
How to write text on a page.

Write text with formatting
How to format the text on your page with HTML tags.


JavaScript Tutorial

Study our Complete JavaScript tutorial


Previous Next

From http://www.w3schools.com (Copyright Refsnes Data)