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...
imagesharkAsked:
Who is Participating?
 
imagesharkConnect With a Mentor Author Commented:
It was failing on this section of code:

.filter(function(){ // this filter contributed by "mindinquiring"
                    var media = $(this).attr("media");
                    return (media.toLowerCase() == "" || media.toLowerCase() == "print")
                })

It said it couldn't find "media", but I did have a media=print in head section.
I commented out this small section of code in query.printarea.js.
It seems to work now, I tested it in Safari and FF, IE9.
0
 
Dave BaldwinFixer of ProblemsCommented:
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.
0
 
Dave BaldwinFixer of ProblemsCommented:
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.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
designatedinitializerCommented:
0
 
imagesharkAuthor Commented:
I found that, and I'm trying it, but I can't seem to get it to work.
0
 
designatedinitializerCommented:
check your browser's error console. What does it say?
0
 
Michel PlungjanIT ExpertCommented:
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

0
 
imagesharkAuthor Commented:
Solution is working!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.