• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Odd jscript problem

xoggoth

More fingers than teeth
Joined
Jul 8, 2005
Messages
17,132
Likes received
4,950
Thanks received
1,184
Location
xoggoth towers
In my mapping thing I've got an info box to provide image and text details when I hover over a pin. The text is within the simplest possible div:

<div id="info"></div>

Just sometimes, not always, it doesn't work and in the console it says:

Cannot set property innerHTML of null at this line:

document.getElementById('info').innerHTML = "";

Can't see any reason why a basic div is seen as null just sometimes. Can't be that it isn't loaded as elements after it are all visible and I added onload to the body to check it has all loaded. In any case the Bing map API setup where the mouseover addHandler is added only triggers at onload.

Any ideas? Ta.
 
Last edited: 20:18
It is very likely that you are setting up this property through script before even it becomes visible to the script. Could it be the case? Make sure <div id="info"></div> exists before the script is run.
 
Thanks BigDataPro but if the onload is complete doesn't that mean the div should be visible? Maybe I should put all the jscript at end not start of page?

PS like the name. I must be SmallDataAmateur
 
It is very likely that you are setting up this property through script before even it becomes visible to the script. Could it be the case? Make sure <div id="info"></div> exists before the script is run.

This is your answer.
 
Great, not heard of defer. Thanks.
 
Ah! Nostrils! Neither defer nor moving the script to bottom of page has worked. Must be some odd fault somewhere. Thanks anyway.
 
An alert at top of script shows correct innerHTML content every time I refresh the page. Then the property is null when I try and use it in mouseover.
 
Last edited: 10:42

Advertisers

Back
Top