HTML Javascript

By using HTML Javascript user can make the pages more dynamic and interactive.

<!DOCTYPE html>

<h1>My First JavaScript</h1>

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

<p id="demo"></p>



HTML Script Tag

The <script> tag is used to define a client-side script.

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

Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content.

document.getElementById(“demo”).innerHTML = “Hello JavaScript”;

Some Functions which illustrate the use of Javascript:

Javascript can change HTML content

document.getElementById(“demo”).innerHTML = “Hello JavaScript”;

Javascript can change HTML styles

document.getElementById(“demo”).style.fontsize = “25px”;
document.getElementById(“demo”).style.color = “red”;
document.getElementById(“demo”).style.backgroundColor = “red”;
JavaScript can change HTML attributes

document.getElementById(“image”).src = “picture.gif”;

The HTML <noscript> Tag

The <noscript> tag is used to provide an alternate content for users that have disabled scripts in their browser or have a browser that doesn't support client-side scripts.

document.getElementById(“demo”).innerHTML = “Hello JavaScript”;

<noscript> Sorry, your browser does not support Javascript! </noscript>