Xerath
Xerath

Reputation: 1099

javascript: alert values of a table row

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"));
        }

Upvotes: 0

Views: 2750

Answers (3)

Mustafa sabir
Mustafa sabir

Reputation: 4360

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

Upvotes: 2

Alex W
Alex W

Reputation: 38193

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

'innerText' works in IE, but not in Firefox

Upvotes: 3

Sarath
Sarath

Reputation: 9156

Use .innerText instead of .innerHTML

Upvotes: 1

Related Questions