So, if declaring the counter using var makes it local to the function, would this be the correct way to initialize it in the following code snippet?
Code:
function foo(bar)
{
if (typeof counter == 'undefined') var counter = 0;
counter++;
var myDiv = document.getElementById(bar);
//additional code follows...
}
The idea being, as the function is called, it initializes the variable if it hasn't been called before. Otherwise, increment the variable by one.