Q:

How Do I Modify This Code From getByID to getByClass?

I have been using the following code to replace various text within an id on my page:
function setInnerHTML(elementId, innerHTML) {
    var el = document.getElementById(elementId);

    if (el) {
        el.innerHTML = innerHTML;
    }
}

However, I now need to apply it to more elements and need to change it to using class instead of id. I understand you need to use getElementsByClassName, but can't get it to work.
Can anyone give me a hand?

A:

function setInnerHTML(elementClass, innerHTML) {
  var elems = document.getElementsByTagName('*'), i;
  for (i in elems) {
    if((' ' + elems[i].className + ' ').indexOf(' ' + elementClass + ' ') > -1) {
        elems[i].innerHTML = innerHTML;
    }
  }
}

