Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8199215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:07:32+00:00 2026-06-07T06:07:32+00:00

I have a webpage with several divs. User should be able to print one

  • 0

I have a webpage with several divs. User should be able to print one div (selected content) or the entire page. If the users prints the entire page it should maintain the header, footer, etc. I can make it print either one section or the entire page, but I can’t figure out how to do both gracefully. My current css is using the @media print like so:

  @media print
   {
    body * { visibility: hidden; }
    .printArea * { visibility: visible; }
   }

Using jQuery, I added the class printArea to the selected section and then called window.print().

$("a.printSection").live("click", function(){
    //the id of the sectionToPrint is actually passed in via metadata plug-in
    $("div#sectionToPrint").addClass('printArea');
    window.print();
});

I have tried adding and removing a class to the body but the issue is that jQuery removes the class name before the job actually prints. Any ideas on how I could print a section or the entire page? The true problem comes in when you print a section and then use ctrl + p to print.

Thanks in advace!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:07:33+00:00Added an answer on June 7, 2026 at 6:07 am

    First of all, you should separate the content from header and footer. Use the following code to see the working example:

    <!DOCTYPE html>
    <html>
        <head>
            <script type="text/javascript" 
               src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
            <script type='text/javascript'>
                var isSelected = false;
    
                // To print the entire page
                function printAll() {
                    $('style[media=\"print\"]').remove();
                    isSelected = false;
                }
                // To print the slected content
                function printSelected() {
                  if(!isSelected) {
                    $('<style type=\"text/css\" media=\"print\">body{visibility:hidden}\
                         .printArea{visibility:visible}</style>').appendTo('head');
                         isSelected = true;
                    }
                }
            </script>
        </head> <body>
            <a href="#" onclick="printAll();return false;">Print All</a>
            <a href="#" onclick="printSelected(); return false;">Print Selected</a>
            <div id="header"> header content here </div>
            <div id="content">
                body content outside the print area
                <div class="printArea">body content inside the print area</div>
                more body content outside the print area
             </div>
            <div id="footer"> footer content here </div>
        </body>
    </html>
    

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webpage with a div which contains several other divs WITHOUT an
I have several thumbnail pics on my webpage. When a user clicks on one
I have a webpage which content(single div and a lot of text with formatting)
In my webpage (Eg Link1: http://localhost:8086/MyStrutsApp/login.do ) I have several links. When a user
I have created a simple webpage with several images, but when a user visits
We have a page of search results which the user can hit in several
On my web page, I'd like to have a group of several concentric circles
I have a webpage including the following div: <div class='book_box'> <table border=0 cellspacing=0> <tr>
I have a webpage that when landed on, will detect a user's physical location
I have a webpage that has to be displayed in several different languages based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.