Udostępnij za pośrednictwem


document.getElementbyId returns null

I had a strange issue today.

document.getElementbyId returns null, but the object was present in the view source .

then I figured out that the javascript was executed on page load ,before the object was rendered.

Solution:

I set the defer property for the script tag, it worked


<

scripttype="text/javascript"language="javascript"defer>

Comments

  • Anonymous
    June 21, 2010
    Thanks for sharing It helped me a lot

  • Anonymous
    March 16, 2011
    Thank you!!!!!

  • Anonymous
    May 12, 2011
    I did a search on the defer tag earlier, and the page said the defer tag was supported by IE only.  Might want to follow-up on that.  Careful!