How To Embed Script In Html

Table of contents:

How To Embed Script In Html
How To Embed Script In Html

Video: How To Embed Script In Html

Video: How To Embed Script In Html
Video: 4: How to Include JavaScript in Our HTML | JavaScript Tutorial | Learn JavaScript | For Beginners 2024, May
Anonim

HTML is a markup language for web pages that is responsible for displaying graphical and textual elements. It can also be used to apply scripts written in various programming languages. A special element is used to insert a script into HTML.

How to embed script in html
How to embed script in html

Instructions

Step 1

The code can be inserted into the page both in the body of the document and in the section. You can use an unlimited number of elements to add active content. The main thing is that the added scripts do not interfere with the display of the main content. To edit HTML code, open your page in any text editor. Webmasters most often use programs that have highlighted descriptors in their functionality: Notepad ++, Web Development Studio, HTML Reader. The required file can also be opened using the standard Notepad application of the Windows operating system.

Step 2

In the text editor window, enter the HTML code. For example, to inject JavaScript into a page, use the following command:

Code to execute

The specified code will be executed on page load and will be executed within the descriptor. In this case, the type parameter lets the handler know that the JavaScript programming language will be used next.

Step 3

In order for the script to process a specific event, for example, when a button is pressed, it must be inserted inside a function. In the section, specify the script code:

Function displayDate ()

{document.getElementById (“perform”). innerHTML = Date (); }

This JavaScript code is responsible for displaying the current time on the page; however, to display it on the monitor, you need to enter an additional command to process the text generated during operation.

Step 4

In the body of the document using HTML, create a button that will be responsible for activating the element:

Show time

This code creates a JavaScript handler button. After clicking it, the result of the script will be displayed.

Step 5

To include in HTML an external script program located in a specific file, you need to run the following code:

Once executed, the specified script named file.js will be included in the page. It is worth noting that the external file must contain no elements for a successful addition.

Recommended: