RESULT OF GETELEMENTBYID IS NULL USING JAVASCRIPT?

Chintoo Semi

Total Post:135

Points:947
Posted by  Chintoo Semi
 1210  View(s)
Ratings:
Rate this:
Hi Mindstick!

Down vote favorite

Just struggling with a Javascript class being used as a method for some cometishian code, how do I have a constructor for this code? The following code is invalid:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">   

<html>   

    <head>   

        <link rel="Stylesheet" href="gStyle.css" />           

        <script type="text/javascript" language="javascript">   

            // Gantt chart object

            function ganttChart(gContainerID) {   

                this.isDebugMode = true;

                this.gContainer = document.getElementById(gContainerID);   

                if (this.isDebugMode) {

                    this.gContainer.innerHTML += "<div id=\"gDebug\">5,5 | 5.1</div>";

                }   

            }               

            var myChart = new ganttChart("chart1");                 

        </script>           

    </head>   

</html>   

<body>   

    <div id="chart1" class="gContainer"></div>   

</body>   

</html>

thanks in advance
  1. shreesh chandra shukla

    Post:105

    Points:735
    Re: Result of getElementById is null using javascript?

    Hi!

    <script type="text/javascript">

    var prevOnload = window.onload || function () {};

    window.onload = function () {

    prevOnload();

    // do your stuff here

    };

    </script> 

    Also, untill all images are fully loaded onload will not trigger, consider using jquery & $(document).ready or similar.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!