Skip to content

Instantly share code, notes, and snippets.

@sixlive
Last active August 29, 2015 14:07
Show Gist options
  • Save sixlive/55b9630cc105676f842c to your computer and use it in GitHub Desktop.
Save sixlive/55b9630cc105676f842c to your computer and use it in GitHub Desktop.
JS: Print Specific Content
( function($) {
/**
* Prints single div content. Adds a class to the body of 'js-print' for
* targeting specific styles.
*
* @return void
*/
$.fn.printDiv = function() {
var printContents = $(this).html();
var originalContents = $('body').html();
$('body').html(printContents);
$('body').addClass('js-print');
window.print();
$('body').html(originalContents);
$('body').removeClass('js-print');
};
})(jQuery);
@sixlive
Copy link
Author

sixlive commented Oct 11, 2014

Updated to add class to the body for print specific style targeting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment