IBMdig
IBMdig

Reputation: 163

Modifying @media print using jQuery

Is there a way to manipulate the @media print with jQuery?

I have a table and I want to count the rows and if the number of rows is greater than a specific number I would apply the page-break-after

$('.print').on('click', function () {
    var r = 0;
    $('.invoice table tbody tr').each(function () {
    r+=1;
    if(r == 30){
        if($('.footer').css('display') == 'none'){
            $('.invoice table tbody').css('page-break-after', 'always');
        }
    }
})

Where

Upvotes: 0

Views: 1317

Answers (1)

charlietfl
charlietfl

Reputation: 171669

Use a css style rule for a class and add that class where applicable. Something like:

var numRows = $('.invoice table tbody tr').length;

if(numRows >= 30 && !$('.footer:visible').length ){
   $('.invoice table tbody').addClass('page-break-class')
}

CSS

@media print {
    tbody.page-break-class {page-break-after: always;}
} 

Upvotes: 1

Related Questions