How to erase what is written by "document.write()"
<p>I am currently working on writing small game that is written in javascript, alot like "snake".  Part of it is that me showing grid and that grid needs to be updated often.</p>

<p>And one way for me to do that is using below function.</p>

<pre><code>function loadImages(){

    for(var i = 0;i&lt;HEIGHT;i++){
        for(var j = 0;j&lt;WIDTH;j++){
            if(grid[i][j] == -1){
                document.write('&lt;IMG SRC="wall.png" width="30"&gt;');
            }
            else if(grid[i][j] == 0){
                document.write('&lt;IMG SRC="empty.png" width="30"&gt;');
            }
        }
    }

    setTimeout( loadImages(), 50 );
}
</code></pre>

<p>Only problem is that when loadImages() function is called over and over, images are concatenated not, replacing.  </p>

<p>So my questions is that is there a way to overwrite document, or clear?</p>

<p>P.S. "document.clear()" function doesn't seems to be all that helpful.</p>

<p>Thank you</p>
