JavaScript is a Scripting Language

A scripting language is a lightweight programming language. JavaScript is programming code that can be inserted into HTML pages. JavaScript inserted into HTML pages, can be executed by all modern web browsers.

<!DOCTYPE html>
<html>
<body>
<p>
JavaScript can write directly into the HTML output stream:
</p>
<script>
document.write(“<h1>This is a heading</h1>”);
document.write(“<p>This is a paragraph.</p>”);
</script>
<p>
You can only use <strong>document.write</strong> in the HTML output.
If you use it after the document has loaded (e.g. in a function), the whole document will be overwritten.
</p>
</body>
</html>

Changing HTML Content:

<!DOCTYPE html>
<html>
<body>
<h1>My First JavaScript</h1>
<p id=”demo”>
JavaScript can change the content of an HTML element.
</p>
<script>
function myFunction()
{
x=document.getElementById(“demo”); // Find the element
x.innerHTML=”Hello JavaScript!”; // Change the content
}
</script>
<button type=”button” onclick=”myFunction()”>Click Me!</button>
</body>
</html>

Changing HTML Styles:

<!DOCTYPE html>
<html>
<body>
<h1>My First JavaScript</h1>
<p id=”demo”>
JavaScript can change the style of an HTML element.
</p>
<script>
function myFunction()
{
x=document.getElementById(“demo”) // Find the element
x.style.color=”#ff0000″; // Change the style
}
</script>
<button type=”button” onclick=”myFunction()”>Click Me!</button>
</body>
</html>

Comments are closed.