Thursday, 7 June 2018

Chaudhari Karan

JavaScript – Placement

    1 comment:


JavaScript – Placement

Hello friends, In this lecture, we will discuss  JavaScript Placement.
JavaScript – Placement


There is the flexibility given JavaScript code anywhere in an HTML document. Here is the JavaScript in an HTML file are as follows:
  • ·         JavaScript in <head>...</head> section.
  • ·         JavaScript in <body>...</body> section.
  • ·         JavaScript in <body>...</body> and <head>...</head> sections.
  • ·         JavaScript in an external file and then in <head>...</head> section.

Here we place JavaScript in an HTML file in different ways.

JavaScript in <head>...</head> section

Example:
JavaScript in <head>...</head> section


Output:
JavaScript in <head>...</head> section

JavaScript in <body>...</body> Section

If JavaScript to run as the page loads so it is generates content in the page, then it is goes in the <body> portion of the document.

Example:
JavaScript in <body>...</body> Section

Output:
JavaScript in <body>...</body> Section

JavaScript in <body> and <head> Sections

Example:
JavaScript in <body> and <head> Sections

Output:
JavaScript in <body> and <head> Sections

JavaScript in External File


For more extensive work with JavaScript, find cases where are reusing identical JavaScript code on multiple pages of the site.

In multiple HTML files doesn't restrict to maintaining identical code. The script tag mechanism to store JavaScript in an external file and then include it into HTML files.   

Here is an example to include an external JavaScript file in HTML code using script tag and its src attribute.
JavaScript in External File


To use JavaScript as the external file source, then write JavaScript source code in the text file with the extension ".js".

For example, create JavaScript file with the name filename.js and then use the sayHello function in your HTML file after including the filename.js file.

JavaScript in External File


Subscribe to this Blog via Email :

1 comments:

Write comments
yogesh kumar
AUTHOR
22 November 2018 at 03:54 delete

This is an awesome post. Really very informative and creative contents. This concept is a good way to enhance knowledge. I like it and help me to development very well. Thank you for this brief explanation and very nice information. Well, got good knowledge.
WordPress development company in Chennai

Reply
avatar