Print only particular div using css and javascript


First we see, how can we do that using css
<style type=”text/css” media=”print”>

@media print{

body *{ visibility: hidden; }

#divname * {visibility: visible; }

#divname {position :absolute; top:40px; left:40px; }

}

</style>

 

Now we see how can done using javascript

<script type=”text/javascript”>

function printDiv(divname){

var printContents = document.getElementById(divname).innerHTML;

var originalContents = document.body.innerHTML;

document.body.innerHTML = printContents;

window.print();

document.body.innerHTML = originalContents;

}

</script>

 

Advertisements

4 thoughts on “Print only particular div using css and javascript

  1. How can I Print more div and paragraphs in a specific format..?
    Eg:
    Name:
    Address:
    DOB:
    Email:
    Contact No:
    etc…..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s