Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Print command

i want print command to work while selecting certain no. of check boxes and then using print button and also want to print multiple divs together.

1 Answer

If I understand you correctly, you want to allow the user to select options on the page which change the way the page prints? I would think the best way to do this it to have the javascript modify a print @media query depending on what options the user has checked. And then just bring up the print dialog with window.print() when the button is pressed.

Can you give an example?

Something on the lines of (jquary):

if($('#printModSelected').attr('checked')) {
   $('<style>@media print
 { #foo { color: blue; } }</style>').appendTo('head');
}

Warnning: script is untested and just a general layout.

Its saying if your checkbox is checked apply this style inside an @media on this element.