Thursday, August 26, 2010

The Difference Between HTML and JavaScript

When the browser is reading in a HTML document it needs to be able to determine what text is HTML and therefore what to display in the browser window, and what text is JavaScript source code to be interpreted and executed. One way to let a browser know that part of an HTML document is JavaScript is to enclose it inside the HTML <SCRIPT></SCRIPT> tags as illustrated above. A browser that knows how to interpret Javascript will attempt to interpret text inside the script tags while reading and displaying HTML elements correctly.

Script tags are most often placed inside the head or body tags but may also be placed inside other elements. Not every version of every browser correctly interprets JavaScript code when script tags are placed inside other HTML elements such as table data cells.

JavaScript Statements and Source Code

The JavaScript text is often referred to as "source code" or just "code" and is made up of statements. In the example first javaScript post these two JavaScript statements:

document.write("<P>Script tags can be placed ")
document.write("in the Head of an HTML document.</P>")

write some text, considering of an HTML paragraph, into the Web page being loaded by the browser. The first statement writes the first half of the paragraph and the second writes the last half. A full description of the parts of these statements is provided later but the net effect is to make the text:

<P>Script tags can be placed in the Head of an HTML document.</P>

part of the HTML document.

No comments:

Post a Comment