get data from column in table js

Solutions on MaxInterview for get data from column in table js by the best coders in the world

showing results for - "get data from column in table js"
Mariam
24 Jan 2019
1function getDataFromColumn(table_id, col) {
2    var tab = document.getElementById(table_id);
3    var n = tab.rows.length;
4    var i, s = null, tr, td;
5    var ss = '';
6
7    if (col < 0) {
8        return null;
9    }
10
11    for (i = 1; i < n; i++) {
12        tr = tab.rows[i];
13        if (tr.cells.length > col) { 
14            td = tr.cells[col];      
15            ss += ' ' + td.innerText + ',';
16        } 
17    }
18    return ss;
19}
20
21var txt =getDataFromColumn('table_ID', 5);