Print the Div Contents in Php or Javascript

The JavaScript is below..

<script type="text/javascript">
var base_url="<?php echo $this->request->webroot; ?>";

function printDivContents(divID="xshr_print_section") {

    //Get the HTML of div
    var divElements = document.getElementById(divID).innerHTML;
    
    Popup(divElements);
}


function Popup(data) {
    var mywindow = window.open('', 'new div', 'height=400,width=600');
    mywindow.document.write('<html><head><title></title>');
    mywindow.document.write('<link rel="stylesheet" href="'+base_url+'"css/print.css" type="text/css" />');
    mywindow.document.write('</head><body >');
    mywindow.document.write(data);
    mywindow.document.write('</body></html>');

    mywindow.print();

    return true;
}
</script>

The HTML file is like-

<div id="xshr_print_section">
<!-- here the printing Contents -->

-
-
-
</div>