I have tried so bad with no luck to get the name of a column of a table by using Javascript. I just want to get the text inside a th tag:
<th data-visible="false" id="th-0">The column name</th>
I have tried this:
var columna = document.getElementById('th-'+key).innerHTML;
And I just get either the error:
Uncaught TypeError: Cannot read property 'innerHTML' of null
or nothing when I try
var column = $('#th-'+key).text();
The key var comes fro ma loop because I am using bootstrap table where i want to show additional information if the user clicks on a plus button:
function detailFormatter(index, row) {
var html = [];
var columns_number=document.getElementById('table').rows[0].cells.length;/*http://stackoverflow.com/a/10043799/1883256*/
console.log('The number of columns is: '+columns_number);
$.each(row, function (key, value) {
if(!isNaN(key)){/*http://stackoverflow.com/a/9716580/1883256*/
console.log('Key value is: '+key);
var column = $('#th-'+key).text();
html.push('<p><b>' + key + ':</b> ' + value + ' - column: '+ column +'</p>');
}
});
return html.join('');
}
Can anyone shed some light to fix this?