user160820
user160820

Reputation: 15230

Is there a way to print the Contents of a Specific DIV

I have a Pape width different DIVs and a PRINT link. I want that if the user clicks on a Print link should a specific DIV be printed not the whole page.

Upvotes: 0

Views: 196

Answers (2)

EMMERICH
EMMERICH

Reputation: 3474

I think you can use CSS, like so:

@media print {
  body * {
    display:none;
  }

  #divToPrint {
    display:block;
  }
}

but I don't think this is supported on all browsers. The alternative would be to open the contents of the DIV in a new window, and then print that window.

Upvotes: 4

Quentin
Quentin

Reputation: 944473

Use print media stylesheets to set everything else to display: none (you'll need to construct your markup in such a way that nothing you want to print is a descendent of something you do want to print).

Toggle class names on the div elements to select which ones get printed.

Upvotes: 0

Related Questions