Skip to content

Latest commit

 

History

History
34 lines (28 loc) · 1.16 KB

24. JavaScript.md

File metadata and controls

34 lines (28 loc) · 1.16 KB

1. JavaScript

JavaScript is the programming language of the web. It allows to dynamically read and modify the HTML document loaded into memory without the need to reload to see the changes. Similar to CSS, JavaScript can be used inside the HTML or in an external file.

<!-- Demonstrates the usage of JavaScript by dynamically changing the background color of the page -->

<!DOCTYPE html>

<html lang="en">
    <head>
        <title>background</title>
    </head>
    <body>
        <button id="red">R</button>
        <button id="green">G</button>
        <button id="blue">B</button>
        <script>

            let body = document.querySelector('body');
            document.querySelector('#red').addEventListener('click', function() {
                body.style.backgroundColor = 'red';
            });
            document.querySelector('#green').addEventListener('click', function() {
                body.style.backgroundColor = 'green';
            });
            document.querySelector('#blue').addEventListener('click', function() {
                body.style.backgroundColor = 'blue';
            });

        </script>
    </body>
</html>