Why does it log out "null" on the console on JS?

Hello. This is my code:

function saveInput() {
    console.log("Button clicked from onclick attribute")

let inputBtn = document.getElementById("input-btn")

And it logs out “null”. It’s part of a video tutorial by Per and I’ve copied his entire code, but I keep getting “null”. Please, help.
Thanks all!

You get null when getElementById doesn’t find any element. if you post all your code maybe we can help more

This is the rest:

    <link rel="stylesheet" href="index.css">
    <script src="index.js"></script>
    <input id="input-el" type="text">
    <button id="input-btn" onclick="saveInput()">SAVE INPUT</button>

Make sure to put this line above the closing body tag so the script runs after the HTML has loaded. It was not causing a problem on my end, but it is best practice to avoid the script trying to run before the HTML has loaded.

Oh wow!!! Thank you so much man!!! Something so simple had me about to lose my mind. :sweat_smile: