Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
How to print the contents inside a specific div with all the applied css styling using Javascript?

I have a main div with a class called container that holds the other divs inside it having their respective css stylings such as spaces and positions of elements. I want the contents inside the container div to get printed. I am using javascript for that. However when I click the button the contents in preview become completly plain and have no specified styling. I want the contents to be printed exactly the way it is being displayed with all their respective stylling.

below are the codes.

The name of the css file is doc.css

doc.html this is the container and the divs inside it.

 <div class="container" id="content"> 

        <div class="ttle">

            <p></p>

        </div>
        <div class= "body">

             <p></p>
         </div>
          .
          .
          .

</div>

Javascript

function printable(paravalue){
    var backup = document.body.innerHTML;
    var divcontent = document.getElementById(paravalue).innerHTML;
    document.body.innerHTML = divcontent;
    window.print();
    document.body.innerHTML = backup;
}

Please suggest me how I can print the contents exactly the way they are getting displayed with all the css styling of their respective divs.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!