• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.

Odd jscript problem

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Odd jscript problem

    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 by xoggoth; 22 December 2020, 20:37.
    bloggoth

    If everything isn't black and white, I say, 'Why the hell not?'
    John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

    #2
    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.

    Comment


      #3
      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
      bloggoth

      If everything isn't black and white, I say, 'Why the hell not?'
      John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

      Comment


        #4
        Originally posted by xoggoth View Post

        PS like the name. I must be SmallDataAmateur
        MediumDataEnthusiast?

        Comment


          #5
          Originally posted by BigDataPro View Post
          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.

          Comment


            #6
            Originally posted by xoggoth View Post
            Maybe I should put all the jscript at end not start of page?
            Yep, put script at the bottom of the page so the html will be loaded first, or use 'defer' for external scripts being linked to:

            javascript - Is it necessary to put scripts at the bottom of a page when using the "defer" attribute? - Stack Overflow
            Maybe tomorrow, I'll want to settle down. Until tomorrow, I'll just keep moving on.

            Comment


              #7
              Great, not heard of defer. Thanks.
              bloggoth

              If everything isn't black and white, I say, 'Why the hell not?'
              John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

              Comment


                #8
                Ah! Nostrils! Neither defer nor moving the script to bottom of page has worked. Must be some odd fault somewhere. Thanks anyway.
                bloggoth

                If everything isn't black and white, I say, 'Why the hell not?'
                John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

                Comment


                  #9
                  got a link to the page?

                  Comment


                    #10
                    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 by xoggoth; 23 December 2020, 11:21.
                    bloggoth

                    If everything isn't black and white, I say, 'Why the hell not?'
                    John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

                    Comment

                    Working...
                    X