Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print a part of my page using jQuery?

I would like to print only certain part of my page. My sample code follows:

<%@ page contentType="text/html;charset=ISO-8859-1" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
        <title>Insert title here</title>    
    </head>
    <body>
        <div class="body">
            Blah... blah... 
        </div>
        <div class="printable">
           contents goes here...
        </div>
    </body>
</html>

I need to print the contents of <div class="printable"></div>. Is it possible to do this using jQuery? Should I write this solution, or is there a plugin that would help solve this problem?

like image 617
maaz Avatar asked Sep 16 '11 06:09

maaz


1 Answers

Add to HTML head:

<link rel="stylesheet" type="text/css" media="print" href="print.css" />

print.css

body * { display: none; }
.printable { display: block; }

Javascript

window.print();
like image 63
mVChr Avatar answered Oct 02 '22 14:10

mVChr