jQuery for loop code change

forEach was throwing an eception in IE8 so to make compatable switched
the loop code to $.each.