0

I'm trying to alert only values without html tags from a selected table row. What's wrong with the following function:

        function show_table_row(row) {
            var arr = [];
            var t_row = document.getElementById("table_id").rows[row].innerHTML;
            for (var i = 0; i < t_red.length; i++)
            {
               arr.push(t_row [i]);
            }
            alert(arr.join("\n"));
        }
Xerath
  • 1,069
  • 5
  • 17
  • 26
  • 1
    Where are you calling this function? What's the value of `row` being passed to the function..? How does the html look like, does it only have text nodes or does it have inner HTML content... – T J Jun 10 '14 at 12:41

3 Answers3

3

Use .textContent because .innerText is not a standardized W3 property.

'innerText' works in IE, but not in Firefox

Community
  • 1
  • 1
Alex W
  • 37,233
  • 13
  • 109
  • 109
2

Change your innerHTML to innerText

var t_row = document.getElementById("table_id").rows[row].innerText;

Edit:- Thanks to Alex W for poitning out , you can use .textContent , since firefox does not support innerText. It is otherwise supported on all major browsers. But note that .textContent is not supported on older versions of IE (before IE9) http://www.quirksmode.org/dom/w3c_html.html

Mustafa sabir
  • 4,130
  • 1
  • 19
  • 28
1

Use .innerText instead of .innerHTML

Sarath
  • 9,030
  • 11
  • 51
  • 84