JSFiddle - React, Tailwind, and code Playground

HTML

<button id="print" onclick="print('uname');" >Print</button>
<div id="uname">
<label>Name</label>
<label>Spider</label>
</div>

JavaScript

function print(e){
var restorepage = $('body').html();
var printcontent = $('#' + e).clone();
 var divToPrint=document.getElementById('e');

        var newWin=window.open('','Print-Window');

        newWin.document.open();

        newWin.document.write('<html><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>');

        newWin.document.close();

        setTimeout(function(){
            newWin.close();
        },10);
}