Print div using Javascript

Here is a full code to print contents of a div using javascript. Just create a div and give any id to it and then create an anchor tag as given below :

<a href="javascript:void(0);" onclick="printdiv('IDOFDIV')">Print</a>

After creating this anchor tag put the below javascript code in your page.

function printdiv(printpage) {

var newstr = document.getElementById(printpage).innerHTML;

var oldstr = document.body.innerHTML;

document.body.innerHTML =newstr;


document.body.innerHTML = oldstr;

return false;