Reputation: 612
I have below the html and I want to add the innerHTML of div tag.
<li id="liFlashDetectionMessage" class="width730 height30 divfloatleft marginleft15">
<div id="divFlashDetectionMessage" class="divfloatleft marginleft5 width730">
</div>
</li>
I have written below but it is giving javascript error.
document.getElementById("divFlashDetectionMessage").innerHTML = "Oops, flash player is not installed on your browser.";
Can anyone help how to do it?
Upvotes: 1
Views: 4452
Reputation: 33865
Without having seen your full code, I bet your code is run before the DOM is ready.
Since the browser parse your code from top to bottom and execute any JavaScript immediately, if your <script>
tag is put before the actual <div>
element you try to manipulate, in your source, then it won't find a match when you run document.getElementById()
because at the time that piece of code is execute, the browser still doesn't know about the tag you declare further down the page.
Try moving your script-element to the bottom of your page, just before your closing </body>
tag.
If you can't/don't want to move your JavaScript, then you would have to listen for the DOM-ready event the browser fires as soon as the DOM is ready, and execute the code when you know the DOM is ready.
Upvotes: 3