Open In App

HTML JavaScript

Last Updated : 18 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

HTML JavaScript is the most popular programming language that helps to add interactivity and provides dynamic behavior. It is known as the client-side scripting language for web pages. JavaScript is used for various purposes, including DOM manipulation, asynchronous requests (AJAX), event handling, fetching external API, and creating interactive web applications.

Additionally, After ES6 JavaScript becomes more popular and provides various functionalities for creating dynamic web pages.

Integrating JavaScript using HTML <script> Tag

The HTML <script> tag is used to integrate JavaScript code or give reference through the attribute “src” for external JavaScript files within an HTML document.

With the help of JavaScript, we can dynamically manipulate the HTML elements. Various HTML JavaScript operations can be done including, DOM manipulation, Adding or removing Style to the element, and adding or removing elements from the DOM.

Note: The most common operation done in JavaScript is finding the HTML elements.

Example: Illustration of the basic example of JavaScript that finds the element by tag name and styles the text with green.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,
                                   initial-scale=1.0">
    <title>HTML JavaScript</title>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h3>HTML JavaScript</h3>
  
    <script>
        const h1element = document
                          .getElementsByTagName("h1")[0];
        h1element.style.color = "green";
    </script>
</body>
  
</html>


Output

HTML-JS

HTML <noscript> Tag

The HTML <noscript> tag is used to provide information displayed when a browser does not support or has disabled JavaScript in their browser.

Note: If the JavaScript is supported by your browser, the text inside the <noscript> tags will not rendered to the User Interface.

Example: Illustration of the basic example of HTML <noscript> tag.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,
                                   initial-scale=1.0">
    <title>HTML JavaScript</title>
</head>
  
<body>
    <h1 id="gfg">GeeksforGeeks</h1>
    <h3>HTML JavaScript</h3>
  
    <script>
        const h1element = document
            .getElementById("gfg");
        h1element.style.color = "green";
    </script>
    <noscript>The browser you are using
        doestnot support JavaScript.
    </noscript>
    <p>If the JavaScript is supported by your browser the
        text inside the noscript tag will not be shown to you.
    </p>
</body>
  
</html>


Output:

htmljs



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads