skip to Main Content

I am creating a invoice software in html, css, and javascript. I fetched with document.getElementById(), but in console is showing null value I searched a lot on internet i found that js file is loading earlier than my html file. Please tell solution.

I tried many times but did not succeed

2

Answers


  1. you can try it by giving it between the body and the html closing tag so that your html file loads first then the js file.

    Login or Signup to reply.
  2. If you are using an external script, use the defer attribute:

    <script src="some_script.js" defer><script>
    

    If you’re using an inline script, use type=module:

    <script type="module">
        x = document.getElementById("your_id");
        console.log(x);
    </script>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search