1

I'm trying to print a table but it captures the whole page and in mobile mode, I would like to just print the addr-table class as below:

HTML

<table class="addr-table">

 ... table content...

</table>
<a href="#" class="js-print-link">Print</a>

JS

<script>

    $('.js-print-link').on('click', function() {
      var printBlock = $(this).parents('.addr-table').siblings('.addr-table');
      printBlock.hide();
      window.print();
      printBlock.show();
    });      
</script>

I tried many formats including suggestions on SO, this code performed the best, now the last huddle. How can I capture just the table in normal pc mode not mobile mode

quba
  • 123
  • 9

1 Answers1

2

please try it ... it works correctly:

<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <title>Page Title</title>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <style>
    @media print {
         *{visibility:hidden}
         .printable,.printable *{
            visibility:visible
         }
      }
    </style>
</head>
<body>
    <div>
        this content is not printable
    </div>
    <table class="printable">
        <tr>
            <td>
                ... table content...
            </td>
        </tr>
    </table>
    <a href="#" class="js-print-link" onclick="print()">Print</a>
</body>
</html>
Mehrzad Tejareh
  • 635
  • 5
  • 21