Relation between HTML and JavaScript

This section describes how HTML is related to JavaScript, which is scripting language be used to implement client-side scripts for the HTML document browser to execute.

JavaScript is a scripting language that can be used to implement client-side scripts for HTML document browsers to interact with the user, control the browser, communicate asynchronously, and alter the document content that was displayed.

Here is a good example of an HTML document with JavaScript code included from http://www.w3schools.com/js/js_howto.asp. In this example, JavaScript is used to implement a code logic to allow the user to interact with the button displayed on the browser.

<!DOCTYPE html>
<!-- JavaScript_Example.html
 - Copyright (c) 2014, HerongYang.com, All Rights Reserved.
-->
<html>
<head>
<title>JavaScript Example</title>
<script>
function myFunction() {
   var e = document.getElementById("demo");
   e.innerHTML="My First JavaScript Function";
}
</script>
</head>

<body>

<h1>My Web Page</h1>

<p id="demo">A Paragraph.</p>

<button type="button" onclick="myFunction()">Try it</button>

</body>
</html> 

When the above HTML document is displayed in a browser, a user can click the button to interact with the browser to change document content. See the picture below:
HTML Embedded with JavaScript

Last update: 2014.

Table of Contents

 About This Book

Introduction of HTML

 What Is HTML?

 History of HTML

 Differences between HTML and XHTML

 Relation between HTML and CSS

Relation between HTML and JavaScript

 Relation between HTML and DOM

 Relation between HTML and DHTML

 Relation between HTML and SVG

 Introduction of HTML5 Features

 HTML Document Structure and Content

 HTML Document and Elements Syntax

 References

 PDF Printing Version