Why does this JavaScript work for FF and not IE8

I just found out six months later that IE cannot process this script, and now that my programmer has left, I myself am stuck :-(

It works great in FF

This is the code:

function updateFields(name, value) {
  var elements = getElementsByClass('field_' + name);
  for(var i=0; i<elements.length; i++) {
    var e = elements[i];
    while(e.firstChild != null) { e.removeChild(e.firstChild); }
    e.appendChild(document.createTextNode(value + ' '));*
  } // for i
} // updateFields()

My IE debugger complains about the line marked with *. It says: Error: An unexpected call to a method or access to properties.

Can someone spend some of their precious time helping? Please write the answers as if I were four years old.

function getElementsByClass(cls) {
  var fields = document.getElementsByTagName('*');
  var r = new Array();

  for(var i=0; i<fields.length; i++) {
    var f = fields[i];

    var a = f.getAttribute('class');
    if(a == null)
      a = f.className;

    if(a == null)
      continue;

    var classes = a.split(' ');
    for(var j=0; j<classes.length; j++) {
      if(classes[j] == cls) {
        r.push(f);
        break;
      } // if
    } // for j
  } // for i

  return r;
}

Button

<form>
  <p class="center">
    <input type="button" onclick="javascript:book_wire_transfer();" style="border: none;      border:0;"\>


  <p class="center">
    <img src="http://www.-.com/images/text/arrow_left_small.png" alt="&raquo;" class="middle" />
    <span class="submit">
      <input class="submit" type="submit" value="Book now"  />
    </span>
    <img src="http://www.-.com/images/text/arrow_right_small.png" alt="&laquo;" class="middle" />
    </p>

  </p>
  </form>
+3
source share
3 answers

There are elements that IE8 and below cannot add text nodes, although IE9 and other browsers do.

option element(use optionelement.text)
input element(use inputelement.value)
style element(use styleelement.styleSheet.cssText)
script element(use scriptelement.text)
+2
source

getElementsByClass , , , - , , IE8. , , , DOM.

, , . document.querySelectorAll('.field_' + name) , ; IE8 , , .

EDIT: getElementsByClass , 100% . - getElementsByClass return document.querySelectorAll('.field_' + name) , ... , getElementsByClass , , .

+1

well, remove * at the end

 e.appendChild(document.createTextNode(value + ' '));*
0
source

All Articles