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,029
  • 5
  • 15
  • 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
  • 35,267
  • 10
  • 97
  • 106
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,015
  • 1
  • 18
  • 27
1

Use .innerText instead of .innerHTML

Sarath
  • 8,762
  • 11
  • 46
  • 80