Link to home
Start Free TrialLog in
Avatar of imageshark
imagesharkFlag for United States of America

asked on

using jquery to print a section of a page

Is there a way, using jquery, to print a "section" of a page.

for instance, I have a game schedule in a table. The table is surround by a div called "printarea".

How do I click a printer icon, and the div "printarea" is sent to the printer.
So just the schedule prints, not the entire page, and background, etc...
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

All that normally does is ask the browser to print the page.  What you can do is put the schedule in an iframe and then put the print button in the iframe and print the iframe.
Or... I have one page where a calendar is included from a separate file.  I have button to open only the calendar in the browser to print it.
Avatar of imageshark

ASKER

I found that, and I'm trying it, but I can't seem to get it to work.
check your browser's error console. What does it say?
ASKER CERTIFIED SOLUTION
Avatar of imageshark
imageshark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here is a simple way to just print the content

function printDiv(id) {
  var html = document.getElementById(id).innerHTML; 
// var html = $("#"+id).html(); // jQuery version
  var w = window.open('','_blank');
  w.document.write('<link href="stylesheet.css" rel="stylesheet"/><body onload="window.focus(); window.print">'+html+'</body>');
  w.document.close();
}

Open in new window

Solution is working!