Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error in JS "Uncaught TypeError: Cannot set properties of null (setting 'innerHTML') at call.html:10:58"

I am new to JavaScript
I am trying to print an array using a function document.getElementById
I am getting an error Uncaught TypeError: Cannot set properties of null (setting 'innerHTML') at call.html:10:58

<!DOCTYPE html>
<html>
    <head>
        <title>My information</title>
        <body>
            <h1>My name is Luffy</h1>
            <p>I am a software developer</p>
            <script>
            const programmingLanguage = ["Python", "Java","C"];
                document.getElementById("program").innerHTML=programmingLanguage;
            </script>
        </body>
    </head>
</html>

please help me where did i go wrong

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The problem is that, you are trying to get an element which has the id program, but there is no element which has the id as program.

You can create an element with id program. this will resolve the error.

<!DOCTYPE html>
<html>
    <head>
        <title>My information</title>
        <body>
            <h1>My name is Luffy</h1>
            <p>I am a software developer</p>
            
            <p id="program"></p>
            
            <script>
            const programmingLanguage = ["Python", "Java","C"];
                document.getElementById("program").innerHTML=programmingLanguage;
            </script>
        </body>
    </head>
</html>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading