HTML Tutorials - Herong's Tutorial Examples - v2.30, by Herong Yang
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. 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) 2009 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:
Table of Contents
Differences between HTML and XHTML
►Relation between HTML and JavaScript
Relation between HTML and DHTML
Relation between HTML and MathML
Introduction of HTML5 Features
HTML Document Structure and Content
HTML Document and Elements Syntax
Displayed and Printed HTML Documents
Responsive Design of Web Pages