
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to include JavaScript in HTML Documents?
To include JavaScript in HTML Documents, use the <script> tag. JavaScript can be implemented using JavaScript statements that are placed within the <script>... </script>.
You can place the <script> tags, containing your JavaScript, anywhere within your web page, but it is normally recommended that you should keep it within the <head> tags.
Let us take a sample example to print out "Hello World". We added an optional HTML comment that surrounds our JavaScript code. This is to save our code from a browser that does not support JavaScript. The comment ends with a "//-->".
Here "//" signifies a comment in JavaScript, so we add that to prevent a browser from reading the end of the HTML comment as a piece of JavaScript code. Next, we call a function document.write, which writes a string into our HTML document.
<html> <body> <script> <!-- document.write("Tutorialspoint") //--> </script> </body> </html>
- Related Questions & Answers
- How to include inline JavaScript inside an HTML page?
- How to include an external JavaScript inside an HTML page?
- How to include an acronym in HTML?
- How to include an abbreviation in HTML?
- How to include Modernizr in HTML document?
- How to include CSS in HTML Pages
- How to include the character encoding in HTML?
- How to include an embedded object in HTML?
- How to include an input field in HTML?
- Include keyboard text in HTML
- How to include groups of table columns in HTML?
- How to include the audio/video controls in HTML?
- How to include a title in a fieldset in HTML?
- How do we include big text in HTML?
- How do we include an anchor in HTML?