Wednesday, October 6, 2010

AJAX and accessing DIV elements

In Firefox I encountered a strange problem when using AJAX to access DIV elements.
I was using a timer to repetitively access a DIV element as follows:

Javascript:
var statusEl = document.getElementById('status');
alert('statusEl'+statusEl);
HTML:
<div id="status" />


On the first timed interval, firefox has no problem finding the element and the alert identifies it as an HTMLElement object. But upon subsequent timed intervals, the alert begins to report the statusEl as null!! Very strange indeed.

Solution:

The solution ended up being to change from <div id="status" />
to <div id="status"></div>

No comments:

Post a Comment