1

I have a line of code that is called in the onLoad event of a page, and it works fine. Inside the onload event, other functions are called, and trying the same line of code now returns null.

Code verbatim

riskInStateInputTypeElement = document.getElementById("riskInStateInputType");

Are there any instances where getElementById begins returning null after having returned the correct thing previously?

The line that works and the line that doesn't work are both in the same call stack, not separate events or threads. The Document readyStatus is 'complete' both time, so I dont think its a matter of the page not entirely loaded. Any ideas where I should look?

Sergio
  • 28,539
  • 11
  • 85
  • 132
  • Tee hee. The problem was I was changing some text in the that also contained the element, and in setting the new .innerText, I was also overwriting the interior HTML that described the element. So I was indeed deleting the element programatically! – ColdCode2013 Jun 25 '13 at 18:39

1 Answers1

0

Did you check that it's referring to an element with that id? Maybe you misspelled id="riskInStateInputType" in your <div></div> (or whatever that id is referring to).

Are you deleting the content within that element before you call it the second time perchance?

royhowie
  • 11,075
  • 14
  • 50
  • 67