×
1 Choose EITC/EITCA Certificates
2 Learn and take online exams
3 Get your IT skills certified

Confirm your IT skills and competencies under the European IT Certification framework from anywhere in the world fully online.

EITCA Academy

Digital skills attestation standard by the European IT Certification Institute aiming to support Digital Society development

SIGN IN YOUR ACCOUNT TO HAVE ACCESS TO DIFFERENT FEATURES

CREATE AN ACCOUNT FORGOT YOUR PASSWORD?

FORGOT YOUR DETAILS?

AAH, WAIT, I REMEMBER NOW!

CREATE ACCOUNT

ALREADY HAVE AN ACCOUNT?
EUROPEAN INFORMATION TECHNOLOGIES CERTIFICATION ACADEMY - ATTESTING YOUR PROFESSIONAL DIGITAL SKILLS
  • SIGN UP
  • LOGIN
  • SUPPORT

EITCA Academy

EITCA Academy

The European Information Technologies Certification Institute - EITCI ASBL

Certification Provider

EITCI Institute ASBL

Brussels, European Union

Governing European IT Certification (EITC) framework in support of the IT professionalism and Digital Society

  • CERTIFICATES
    • EITCA ACADEMIES
      • EITCA ACADEMIES CATALOGUE<
      • EITCA/CG COMPUTER GRAPHICS
      • EITCA/IS INFORMATION SECURITY
      • EITCA/BI BUSINESS INFORMATION
      • EITCA/KC KEY COMPETENCIES
      • EITCA/EG E-GOVERNMENT
      • EITCA/WD WEB DEVELOPMENT
      • EITCA/AI ARTIFICIAL INTELLIGENCE
    • EITC CERTIFICATES
      • EITC CERTIFICATES CATALOGUE<
      • COMPUTER GRAPHICS CERTIFICATES
      • WEB DESIGN CERTIFICATES
      • 3D DESIGN CERTIFICATES
      • OFFICE IT CERTIFICATES
      • BITCOIN BLOCKCHAIN CERTIFICATE
      • WORDPRESS CERTIFICATE
      • CLOUD PLATFORM CERTIFICATENEW
    • EITC CERTIFICATES
      • INTERNET CERTIFICATES
      • CRYPTOGRAPHY CERTIFICATES
      • BUSINESS IT CERTIFICATES
      • TELEWORK CERTIFICATES
      • PROGRAMMING CERTIFICATES
      • DIGITAL PORTRAIT CERTIFICATE
      • WEB DEVELOPMENT CERTIFICATES
      • DEEP LEARNING CERTIFICATESNEW
    • CERTIFICATES FOR
      • EU PUBLIC ADMINISTRATION
      • TEACHERS AND EDUCATORS
      • IT SECURITY PROFESSIONALS
      • GRAPHICS DESIGNERS & ARTISTS
      • BUSINESSMEN AND MANAGERS
      • BLOCKCHAIN DEVELOPERS
      • WEB DEVELOPERS
      • CLOUD AI EXPERTSNEW
  • FEATURED
  • SUBSIDY
  • HOW IT WORKS
  •   IT ID
  • ABOUT
  • CONTACT
  • MY ORDER
    Your current order is empty.
EITCIINSTITUTE
CERTIFIED

How can you import JavaScript code into an HTML file?

by EITCA Academy / Monday, 07 August 2023 / Published in Web Development, EITC/WD/JSF JavaScript Fundamentals, Getting started, Adding JavaScript to a website, Examination review

To import JavaScript code into an HTML file, there are several methods available that allow developers to enhance the functionality and interactivity of their web pages. In this answer, we will explore three commonly used techniques: inline script, internal script, and external script.

1. Inline Script:
The inline script method involves embedding JavaScript code directly within the HTML file. This can be achieved by using the `<script>` tag, which is specifically designed to hold JavaScript code. To import JavaScript code inline, you simply need to place the script tag within the `<head>` or `<body>` section of your HTML file. Here's an example:

html
<!DOCTYPE html>
<html>
<head>
  <title>Inline Script Example</title>
  <script>
    // JavaScript code goes here
    function greet() {
      alert("Hello, World!");
    }
  </script>
</head>
<body>
  <h1>Welcome to my webpage</h1>
  <button onclick="greet()">Click me</button>
</body>
</html>

In this example, the JavaScript code is placed within the `<script>` tags in the `<head>` section. The `greet()` function is then called when the button is clicked.

2. Internal Script:
The internal script method involves placing the JavaScript code within a `<script>` tag directly in the HTML file. However, instead of placing the code directly within the `<script>` tags, you can use the `src` attribute to reference an external JavaScript file. This approach helps to keep the HTML file clean and separates the JavaScript code into its own file. Here's an example:

html
<!DOCTYPE html>
<html>
<head>
  <title>Internal Script Example</title>
  <script src="script.js"></script>
</head>
<body>
  <h1>Welcome to my webpage</h1>
  <button onclick="greet()">Click me</button>
</body>
</html>

In this example, the JavaScript code is stored in a separate file called `script.js`. The `<script>` tag with the `src` attribute references this external file. The `greet()` function is defined in `script.js` and can be called from within the HTML file.

3. External Script:
The external script method involves linking an external JavaScript file to the HTML file using the `<script>` tag's `src` attribute. This method is particularly useful when multiple HTML files need to share the same JavaScript code. To import JavaScript code externally, you need to create a separate JavaScript file and reference it in the HTML file. Here's an example:

html
<!DOCTYPE html>
<html>
<head>
  <title>External Script Example</title>
  <script src="script.js"></script>
</head>
<body>
  <h1>Welcome to my webpage</h1>
  <button onclick="greet()">Click me</button>
</body>
</html>

In this example, the JavaScript code is stored in the external file `script.js`. The `<script>` tag with the `src` attribute is used to link the HTML file to the JavaScript file. The `greet()` function is defined in `script.js` and can be called from within the HTML file.

There are three common methods to import JavaScript code into an HTML file: inline script, internal script, and external script. The inline script method involves embedding the JavaScript code directly within the HTML file using the `<script>` tag. The internal script method allows you to place the JavaScript code within a `<script>` tag in the HTML file or reference an external JavaScript file using the `src` attribute. The external script method involves creating a separate JavaScript file and linking it to the HTML file using the `<script>` tag's `src` attribute. Choose the method that best suits your needs based on code organization, reusability, and maintainability.

Other recent questions and answers regarding Adding JavaScript to a website:

  • Why are variables and constants important in JavaScript programming?
  • What is the difference between a variable and a constant in JavaScript?
  • Why is it important to import dependent scripts before using them in your code?
  • What is the recommended placement of the script tag in an HTML file?

More questions and answers:

  • Field: Web Development
  • Programme: EITC/WD/JSF JavaScript Fundamentals (go to the certification programme)
  • Lesson: Getting started (go to related lesson)
  • Topic: Adding JavaScript to a website (go to related topic)
  • Examination review
Tagged under: HTML, Import, JavaScript, Scripting, Web Development
Home » Adding JavaScript to a website / EITC/WD/JSF JavaScript Fundamentals / Examination review / Getting started / Web Development » How can you import JavaScript code into an HTML file?

Certification Center

USER MENU

  • My Account

CERTIFICATE CATEGORY

  • EITC Certification (106)
  • EITCA Certification (9)

What are you looking for?

  • Introduction
  • How it works?
  • EITCA Academies
  • EITCI DSJC Subsidy
  • Full EITC catalogue
  • Your order
  • Featured
  •   IT ID
  • EITCA reviews (Reddit publ.)
  • About
  • Contact
  • Cookie Policy (EU)

EITCA Academy is a part of the European IT Certification framework

The European IT Certification framework has been established in 2008 as a Europe based and vendor independent standard in widely accessible online certification of digital skills and competencies in many areas of professional digital specializations. The EITC framework is governed by the European IT Certification Institute (EITCI), a non-profit certification authority supporting information society growth and bridging the digital skills gap in the EU.

    EITCA Academy Secretary Office

    European IT Certification Institute ASBL
    Brussels, Belgium, European Union

    EITC / EITCA Certification Framework Operator
    Governing European IT Certification Standard
    Access contact form or call +32 25887351

    Follow EITCI on Twitter
    Visit EITCA Academy on Facebook
    Engage with EITCA Academy on LinkedIn
    Check out EITCI and EITCA videos on YouTube

    Funded by the European Union

    Funded by the European Regional Development Fund (ERDF) and the European Social Fund (ESF), governed by the EITCI Institute since 2008

    Information Security Policy | DSRRM and GDPR Policy | Data Protection Policy | Record of Processing Activities | HSE Policy | Anti-Corruption Policy | Modern Slavery Policy

    Automatically translate to your language

    Terms and Conditions | Privacy Policy
    Follow @EITCI
    EITCA Academy

    Your browser doesn't support the HTML5 CANVAS tag.

    • Quantum Information
    • Cybersecurity
    • Web Development
    • Artificial Intelligence
    • Cloud Computing
    • GET SOCIAL
    EITCA Academy


    © 2008-2026  European IT Certification Institute
    Brussels, Belgium, European Union

    TOP
    CHAT WITH SUPPORT
    Do you have any questions?
    We will reply here and by email. Your conversation is tracked with a support token.