I'm trying to apply a dynamic style to all elements on my page with a certain class.

I'm using this getElementsByClassName function...

Code JavaScript:
function getElementsByClassName(className) 
  var arr = new Array(); 
  var elems = document.getElementsByTagName("*");
  for(var i = 0; i < elems.length; i++)
	 var elem = elems[i];
	 var id = elem.getAttribute("id");
	 var cls = elem.getAttribute("class");
	 if(cls == className)
		arr[arr.length] = id;
  return arr;

And getting back an array of all the objects with that class, etc.


So now what ?...

I've been trying this...

Code JavaScript:
<script type="text/javascript">
	bobArray = getElementsByClassName('Bob');
	for( var i in bobArray )
	(bobArray[i]).style.display = 'block';

The "for( var i in bobArray )" part is allegedly the Javascript equivalent of PHP's foreach loop, that loops through every record in an array, doing the same thing to each.

So I'm trying to apply the style to each of the elements like that but getting back the ole "has no properties" error

Quote Originally Posted by Firefox
bobArray[i] has no properties
Any ideas ?