getElementsByClassName



examples/javascript/get_elements_by_class_name.html
<div class="foo">A</div>
<div class="bar">Bar</div>
<div class="foo">C</div>

<script>
var fields = document.getElementsByClassName('foo');
for (var i=0; i < fields.length; i++) {
  //console.log(i);
  fields[i].innerHTML = "Hello foo " + i;
}
</script>