Last active
August 29, 2015 14:07
-
-
Save sixlive/55b9630cc105676f842c to your computer and use it in GitHub Desktop.
JS: Print Specific Content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to add class to the body for print specific style targeting.