//array to fill with ths
var ths = new Array();
//Clean the text
function trimIt(x) {
return x.replace(/(^\s+|\s+$)/g, '');
}
//Fill ths array with header text
$(".table th").each(function() {
var thdatatrimmed = trimIt($(this).html());
ths.push(thdatatrimmed);
});
//total trs
var trlen = $(".table tr").length;
console.log(trlen);
console.log(ths);
//add header to data-title attribute to each TD
$('.table tr').each(function(){
\t $(this).find('td').each(function(index,td){
\t \t //console.log(td,index); \t
$(td).attr('data-title',ths[index]);
});
});
\t .demo {
\t border:1px solid #C0C0C0;
\t border-collapse:collapse;
\t padding:5px;
\t }
\t .demo th {
\t border:1px solid #C0C0C0;
\t padding:5px;
\t background:#F0F0F0;
\t }
\t .demo td {
\t border:1px solid #C0C0C0;
\t padding:5px;
\t }
\t
Table 1 | Table 2 | Table 3 | Table 4 | Table 5 | Table 6 | Table 7 | Table 8 | Table 9 | Table 10 | Table 11 |
---|---|---|---|---|---|---|---|---|---|---|
Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell |
Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell |
Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell |
Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell | Table Cell |