JSFiddle - React, Tailwind, and code Playground
by Prasanth AR
HTML
<body>
<script ></script>
<p>Click the button to print the current page.</p>
<button onclick="open()">Print this page</button>
<div>
<p>Your content here</p>
<table id="toPrint">
<tr>
<td>Neil D'zousa</td>
<td>112233445566</td>
</tr>
</table>
</div>
<div id="notForPrint">
<a href="#" id="print">print</a>
</div>
<script>
</script>
</body>
JavaScript
function open() {
if(!$('#toPrint .header').length)
{
var htmlTable2 = '<tr class="header">' + '<th>Name</th>'
+ '<th>Phone</th>'+ '</tr>';
var html1 = $("#toPrint").prepend(htmlTable2);
}
window.print();
}
$(function() {
$("a#print").click(open);
});