Printing content of a particular div in HTML

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;

<head>

<script type=”text/javascript”>

function PrintDiv() {

var divToPrint = document.getElementById(‘divToPrint’);

var popupWin = window.open(”, ‘_blank’, ‘width=500,height=500’);

popupWin.document.open();

popupWin.document.write(‘<html><body onload=”window.print()”>’ + divToPrint.innerHTML + ‘</html>’);

popupWin.document.close();

}

</script>

</head>

<body >

other contents

<div id=”divToPrint” >

<div style=”width:200px;height:300px;background-color:teal;”>

This is the div to print

</div>

</div>

<div>

<input type=”button” value=”print” onclick=”PrintDiv();” />

</div>

</body>

</html>

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s