---
title: "Result of getElementById is null using javascript?"  
description: "Result of getElementById is null using javascript?"  
author: "Anonymous User"  
published: 2013-08-19  
updated: 2013-08-19  
canonical: https://www.mindstick.com/forum/1397/result-of-getelementbyid-is-null-using-javascript  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# Result of getElementById is null using javascript?

Hi [Mindstick](https://yourviews.mindstick.com/view/84668/how-mindstick-is-used-for-marketing-purposes)!\

Down vote favorite

Just struggling with a [Javascript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript) class being used as a [method](https://www.mindstick.com/forum/166/webservice-method) for some cometishian code, how do I have a constructor for this code? The following code is invalid:

<![DOCTYPE](https://www.mindstick.com/interview/23388/what-is-the-importance-of-the-html-doctype) HTML [PUBLIC](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>

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

<[script](https://www.mindstick.com/interview/477/how-can-i-execute-a-php-script-using-command-line) type="text/javascript" [language](https://www.mindstick.com/startup/28/preply-the-fast-growing-platform-transforming-language-learning)="javascript">

// Gantt chart object

[function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) ganttChart(gContainerID) {

this.isDebugMode = true;

this.gContainer = document.getElementById(gContainerID);

if (this.isDebugMode) {

this.gContainer.innerHTML += "<div id=\"gDebug\">5,5 | [5.1](https://answers.mindstick.com/qa/92571/how-to-work-bluetooth-5-1)</div>";

}

}

var myChart = new ganttChart("chart1");

</script>

</head>

</html>

<body>

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

</body>

</html>

thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)

## Replies

### Reply by shreesh chandra shukla

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.


---

Original Source: https://www.mindstick.com/forum/1397/result-of-getelementbyid-is-null-using-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
