-3

I see this answer, but how to proceed to print text from second, third div? This is what I want to:

<script type="text/javascript">
function PrintElem(elem)
{
    Popup($(elem).text());
}
function Popup(data) 
{
    var mywindow = window.open('', 'Coupon', 'height=300,width=710');
    mywindow.document.write('<html><head><title>Coupon</title>');
    /*optional stylesheet*/ mywindow.document.write('<link rel="stylesheet" href="cupon.css" type="text/css" />');
    mywindow.document.write('</head><body ><div class="coupon_logo"><img src="discount.jpg"></div><div class="coupon_conditions">');
             mywindow.document.write(data); // text from first div
    mywindow.document.write('</div>');
    mywindow.document.write('<div class="coupon_clinic_info">');
            //text from second div
    mywindow.document.write('</div>');
    mywindow.document.write('</body></html>');
    mywindow.print();
    mywindow.close();
    return true;
}

Community
  • 1
  • 1
zzz_z
  • 43
  • 1
  • 6
  • What exactly do you mean by "**print** text from div"? What are you trying to achieve? Please explain your problem properly so that we can help you. – Felix Kling Jul 19 '12 at 11:25

1 Answers1

2

I imagine it would be fine simply applying a class to all the divs you wish to print

<div id="mydiv" class="toprint">
    This will be printed. 
</div>

<div>
    This will not be printed.
</div>

<div id="anotherdiv" class="toprint">
    This will be printed.
</div>

Then using the answer to the question you quoted, changing this line:

<input type="button" value="Print Div" onclick="PrintElem('.toprint')" />
nitsua
  • 763
  • 8
  • 20