Access to element with ID

Saturday 06/08/2022

·1 min read
Share:

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.

Share:
VA

Vadim Alakhverdov

Software developer writing about JavaScript, web development, and developer tools.

Related Posts