HTML5 and JavaScript

Level : Advanced
Mentor: Shailendra Chauhan
Duration : 00:00:45

JavaScript with HTML:

JavaScript is a dynamic programming language commonly used to add interactivity and functionality to web pages. When used with HTML, JavaScript can manipulate HTML elements, respond to user actions, and perform various tasks on a web page.

Example:

<html>
 <head>
    <script>
      function greet() {
        alert("Hello, World!");
      }
    </script>
  </head>
  <body>
    <button onclick="greet()">Click Me</button>
  </body>
</html>

Inline Script in HTML:

An inline script in HTML refers to JavaScript code that is placed directly within the HTML document using the <script> element. Inline scripts are typically used for small, specific functions or event handlers within the HTML file.

Example:

<html>
  <body>
    <button onclick="alert('Hello, Inline Script!')">Click Me</button>
  </body>
</html>

Internal Script in HTML:

An internal script in HTML is JavaScript code that is embedded within the <script> tags within the HTML document. It is usually placed in the <head> or <body> section of the HTML file. Internal scripts are suitable for more extensive JavaScript functions or scripts that need to be reused across multiple pages of a website.

Example:

<html>
 <head>
    <script>
      function calculateSum(a, b) {
        return a + b;
      }
    </script>
  </head>
  <body>
    <p>The sum of 5 and 3 is: <span id="result"></span></p>
    <script>
      document.getElementById("result").textContent = calculateSum(5, 3);
    </script>
  </body>
</html>
Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this