0

Possible Duplicate:
IE 8: Object doesn’t support property or method ‘getElementsByClassName’

I've got a table with generated divs placed within each td, each have a generated classname example: "c1" I can drag say "c1" to another cell I want it to update the textbox (class = cell).

alert(target_cell.className);

//var cellTxt = target_cell.querySelectorAll('.cell');       
var cellTxt = target_cell.getElementsByClassName('cell')[0];

cellTxt.setAttribute('value', target_cell.className);
alert(cellTxt.value);

The target_cell is the new cell but it throws up the error "Object doesn't support property or method" when it tries to update it. I get the same error in IE 8 & 9 using either cellTxt options.

Any Ideas?

Community
  • 1
  • 1
ajl80
  • 49
  • 9
  • 3
    Also there's no reason to use `.setAttribute()` to set the "value" property of a DOM element - just write `cellTxt.value = whatever;` – Pointy Oct 22 '12 at 15:11
  • I think your problem is cellTxt is not an input type of element. Use `innerHTML` as I suggest below. – Sukanta Paul Oct 22 '12 at 15:16

2 Answers2

0

Just set the value of cellTxt if it is the text box.

cellTxt.value = Anything;
Sukanta Paul
  • 784
  • 3
  • 19
  • 36
0

getElementsByClassName() is not a JavaScript function before IE9 (compatibility reference).

Matt Brock
  • 5,337
  • 1
  • 27
  • 26