JavaScript DOM modification
If you have performance issues, then I believe you should first try and profile your script, to identify which function(s) run slowly. There are profilers embedded in most scripting consoles.

Regarding your question: since your code should not trigger any repaint, I believe that method 1 would be fine. Unfortunately, I have not been able to reproduce the issue on my machine, so cannot confirm this answer.

To improve performance, I suppose you could try the following:


Rather than using setInterval, consider chaining setTimeout calls, so that the browser remains responsive.
Try and remove your library, to use native Javascript. It looks like you do not need anything more than getElementById, getElementsByTagName, getAttribute and setAttribute - so should be able to safely eliminate any library overhead.
Possibly cache the retrieval of all the div, as you only need to perform it once.


So basically, try and run the following (untested) on window.onload:

function update() {
    var delay = 100;
    var container = document.getElementById("container");
    var divs = container.getElementsByTagName("div");

    function updateDivs() {
        for (var ii = 0; ii &lt; divs.length; ii++) {
            var div = divs[ii];
            if (randNum(0, 10) == 1) {
                var value = randString();
                if (div.getAttribute("alt") != value) {
                    div.setAttribute("alt", value);
                }
            }
        }
        setTimeout(arguments.callee, delay);
    }

    updateDivs();
}