<p>I've a HTML page with several Div's that will show the time difference between now and each given date.</p>

<pre><code>&lt;div class="dated" onEvent="calculateHTML(this, 'Sat Jun 09 2007 17:46:21')"&gt;
30 Minutes Ago&lt;/div&gt;
</code></pre>

<p>I want that time difference to be dynamic (calculated to all elements when the page loads and also within a time interval)</p>

<p>So, my idea was to go to all div's of class "dated", calculate the time diference for each one and replace the correspondent innerHTML.</p>

<p>Is this the best aproach or should I try a different one?</p>

<p>Edit: 
<br>One of the problems I've encountered was, where do I keep within the div, the date that will be used to generate the text?</p>

Using innerHTML works most (all?) of the time and may frequently be faster than generating a bunch of HTML (i.e. not in this case).
I always prefer using standard methods as shown below, because I know they should never break.  [Note that I don't check the 'class' attribute directly, since an element may have multiple classes.]
```
```
function adjustDates() {
    var i;
    var elms = document.getElementsByTagName("div");
    for (i = 0; i < elms.length; i++) {
        var e = elms[i];

        /* update timestamps with date */
        if (elementHasClass(e, "dated")) {
            var txt = YOUR_DIFFERENCE_CODE(e);
            e.replaceChild(document.createTextNode(txt), e.lastChild);
        }
    }
}
```
```