0

I tried printing a particular div on a dynamic webpage which is a php file.

mY kInG
  • 1
  • 2
  • 2
    Your title is longer than your question.... Imagine a newspaper article like that: Title: "Boat capsized and all 33 people fell overboard. They couldn't swim.". And then the content: "They're dead.". – KIKO Software Dec 15 '22 at 13:23
  • Where exactly are you stuck? Post your code/attempt, example data, expected result from that data and what currently happens (we need details, incl. full error messages, if any.) Also read [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) and [how to ask](https://stackoverflow.com/help/how-to-ask). – M. Eriksson Dec 15 '22 at 13:53
  • It's not clear what you exactly want to do. If you want to print only a part of web page using JS you may check this question: https://stackoverflow.com/questions/12997123/print-specific-part-of-webpage – Geckon01 Dec 15 '22 at 14:15

2 Answers2

0

you can use

echo '<div></div>';
Hamza R123
  • 11
  • 2
  • Why not use `print '
    ';`? I agree that the question is not very clear on what "printing" means, but I think thay mY kinG wants something on paper. That's at least what `window.print()` does, but then for a whole webpage, not a `
    `.
    – KIKO Software Dec 15 '22 at 13:33
0

to print a div you can use:

 <div id="print-div">
...content of div goes here...
</div>

add this function

function printDiv() {
  var printDiv = document.getElementById("print-div");
  var printContent = printDiv.innerHTML;
  var printWindow = window.open("", "", "width=800,height=600");
  printWindow.document.write(printContent);
  printWindow.print();
  printWindow.close();
}

and try with this button

<button onclick="printDiv()">Test Print Div</button>