HTML Javascript

HTML Tutorial

HTML Forms

HTML Graphics

HTML Media

HTML API

HTML Javascript

JavaScript are used to make HTML pages more dynamic and interactive.

Example:

				
					<button type="button"
onclick="document.getElementById('demo').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="demo"></p>

				
			

Output:

The HTML <script> Tag

The HTML <script> tag define a client-side script (JavaScript).

The <script> element contains script statements, or it refers to an external script file through the src attribute.

Some uses of JavaScript are image manipulation, form validation, and dynamic changes in content.

To select an HTML element, JavaScript uses the document.getElementById() method.

This JavaScript example writes “Hello JavaScript!” into an HTML element with id=”demo”:

Example

				
					<p>This example writes "Hello JavaScript!" into an HTML element with id="demo":</p>
<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script> 


				
			

Output:

This example writes "Hello JavaScript!" into an HTML element with id="demo":