To do this, you really need to use a CSS stylesheet for printing, but if you want to achieve your goal this way, it might work better:
$(function(){ $('#button1').click(function(){ $('head').append('<link rel="stylesheet" href="<?php echo base_url() ?>assets/weekly/style/weekly.css" type="text/css"/>'); var printContents = $( $('#data').html() ); var originalContents = $('body > *').hide(); $('body').append( printContents ); window.print(); printContents.remove(); originalContents.show(); }); });
Create a new element using innerHTML of the data element. Hide all children tag body. Add a new element to the body tag. Print out. Delete the new item. Show original content again.
This is still messy, but you should not lose your events.
nderscore
source share