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
susanne
  • 1,219
  • 3
  • 17
  • 26
  • If you have jquery why not simply `var cells = $("#row_1 td")`? – Ash Burlaczenko Nov 21 '12 at 17:03
  • 1
    Yes. If you're using jQuery, then use jQuery... If you're using pure Javascript, then use pure Javascript. I really don't like developers mixing the two without any particular performance-related reasons. – Robert Koritnik Nov 21 '12 at 17:05
  • Why you are using pure Javascript selector and later `Jquery` selectors? Can I see the html code? – Tom Sarduy Nov 21 '12 at 17:06

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
  • 100,870
  • 50
  • 272
  • 398
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
  • 115,009
  • 15
  • 189
  • 197