0

Possible Duplicate:
‘innerText’ works in IE, but not in Firefox

function stopped() {
    var this_row =  document.getElementById("row_1");
    var cells = this_row.getElementsByTagName("td");

    $('#starttime').html(cells[0].innerText);     
}

I have a javascript function above. It fills a form using the value from cells[0]. It works with IE and Chrome. But it cannot work with FireFox browser. I want to know whther there is any problem with my code. Thanks.

Community
  • 1
  • 1
susanna
  • 1,395
  • 3
  • 20
  • 32

2 Answers2

2

The problem is innerText

The problem with your code is (as Dr.Molle also pointed out) the use of innerText property which Firefox doesn't understand as can be seen on QuirksMode page.

Firefox instead understands textContent property.

The solution

Rewrite your function to embrace jQuery and it should work cross-browser because jQuery was written to be a cross-browser library (to make our life easier with individual browser quirks):

function stopped() {
    $("#starttime").html($("#row_1 td:first-child").text());
}
Community
  • 1
  • 1
Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
1

use

$(cells[0]).text();

instead of

cells[0].innerText

innerText is a property introduced by IE and is not a w3c-standard(and not supported by firefox).

Dr.Molle
  • 116,463
  • 16
  • 195
  • 201