You are on page 1of 2

Java Script.

document.write("<h1>This is a heading</h1>"); document.write("<p>This is a paragraph</p>");

You can only use document.write in the HTML output. If you use it after the document has loaded, the whole document will be overwritten.

JavaScript !eactin" to #vents


The alert$% function is not much used in JavaScript, but it is often &uite handy for tryin" out code.

The onclic' event is only one of the many HTML events you will learn about in this tutorial.

<button type="button" onclic ="alert(!"elcome#!)">$lic

%e#</button>

(sin" JavaScript to manipulate the content of HTML elements is a very powerful functionality.

JavaScript )han"in" HTML )ontent

&=document.get'lement(y)d("demo") &.inner+T%,="+ello -a.a/cript";

//*ind the element //$hange the content

JavaScript )han"in" HTML Styles


&=document.get'lement(y)d("demo") &.style.color="0112222"; //*ind the element //$hange the style

JavaScript *alidate Input


i1 is3a3(&) 4alert("3ot 3umeric")

-a.a )nput

<input id="demo" type="text"> var x=document.getElementById("demo").value; i (x==""!!i"#a#(x)) $ alert("#ot #umeric"); %

JavaScript in +head, or +body,


You can place an unlimited number of scripts in an HTML document.

Scripts can be in the +body, or in the +head, section of HTML, and-or in both.

It is a common practice to put functions in the +head, section, or at the bottom of the pa"e. This way they are all in one place and do not interfere with pa"e content.

<script src="my/cript.5s"></script>

#.ternal JavaScript files have the file e.tension ./s.

To use an e.ternal script, point to the ./s file in the 0src0 attribute of the +script, ta"

You might also like