Print a div content using Jquery

前端 未结 13 2227
栀梦
栀梦 2020-11-30 05:22

I want to print the content of a div using jQuery. This question is already asked in SO, but I can\'t find the correct (working) answer.

This is is my HTML:

13条回答
  •  日久生厌
    2020-11-30 06:14

    Below code from codepen worked for me as I wanted,

    function printData()
    {
       var divToPrint=document.getElementById("printTable");
       newWin= window.open("");
       newWin.document.write(divToPrint.outerHTML);
       newWin.print();
       newWin.close();
    }
    
    $('button').on('click',function(){
    printData();
    })
    

    Here is a link codepen

提交回复
热议问题