So I have this code where I'm trying to print(physical print as in paper) a table when a button is clicked, which is populated with array data.
I managed to print the array data but I can not seem to find on how to put this in a table.
also is there a better way than document.write()I am not a huge fan of it ?
var Obj = [];
function printDiv(){
var divContents = document.getElementsByClassName("test")
console.log(divContents)
//if($("div").hasClass("test") == true){// can use jquery hasfind in order to check if acive class exists if yes get content of child divs
//expand if this option is better
//console.log('istrue');
//}
for(var i = 0; i< divContents.length; i++){
Obj.push(divContents[i].textContent +'</br>')
}
var a = window.open('','','height=500,width=500');
a.document.write('<html>');
a.document.write('<body><h1>Div contents are<h1><br>');
a.document.write('<table><tbody><tr>')
a.document.write('<td>'+ Obj.join(' ')+'<td>');
a.document.write('</tr></tbody></table></body></html>');
a.document.close();
a.print();
Obj = [];
}
work order and date are not yet populated this is just a test file to use in a bigger project.
jsfiddle : https://jsfiddle.net/yLz7stxr/
thanks in advance.


document.write()is kinda outdated.