Home  >  Q&A  >  body text

How to print the contents of a DIV in a way that includes pictures?

I have this code. Prints the contents of the DIV by its ID, but omits one picture. I hope you will support me and tell me how to include this image. (The picture is also inside the DIV)

impresion = DIV to print

function printDiv(impresion) {
     var contenido= document.getElementById(impresion).innerHTML;
     var contenidoOriginal= document.body.innerHTML;


     document.body.innerHTML = contenido;

     window.print();

     document.body.innerHTML = contenidoOriginal;
}

I tried many methods but none of them worked

P粉561438407P粉561438407404 days ago481

reply all(1)I'll reply

  • P粉270891688

    P粉2708916882023-09-11 10:56:43

    Here is a simple solution using only CSS:

    @media print {
      body * {
        visibility: hidden;
      }
      #impresion, #impresion * {
        visibility: visible;
      }
      #impresion {
        position: absolute;
        left: 0;
        top: 0;
      }
    }

    reply
    0
  • Cancelreply