Access to element with ID

Tags:
Date:

Saturday 06/08/2022

If you set ID on html element, you can access it inside your script directly

<!DOCTYPE html>
<html>
    <head></head>
    <body>
        <button id="test">Button</button>
        <script>
            console.log(test)
        </script>
    </body>
</html>

The output in the console will be:

<button id="test">Button</button>

It makes the code more complex if you use this functionality of HTML.

© 2023 Vadim Alakhverdov