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.

And one way for me to do that is using below function.

```
function loadImages(){

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

    setTimeout( loadImages(), 50 );
}

```

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

So my questions is that is there a way to overwrite document, or clear?

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

Thank you