Want to print a div section with css... currently print div section is working but not working perfectly because it's can't load css

Want to print a div section with css…

<img title="Print" onclick="printContent('divToPrint')" id="pprint"  src=" " alt=""></img>

   function printContent(el){
var restorepage = document.body.innerHTML;
var printcontent = document.getElementById(el).innerHTML;
document.body.innerHTML = printcontent;
document.body.innerHTML = restorepage;

I also linked stylesheet with this code but not working…

At your id attr you have write “pprint” and not “print”.

Ya I know but it’s just id…

[quote="rajancs5553, post:1, topic:249378"]
&lt;img title="Print" onclick="printContent('divToPrint')" id="pprint"  src=" " alt=""&gt;&lt;/img&gt;

I don’t know if this affects your results, but make sure your html is correct. <img> is self-closing and does not use a closing </img> tag.

If the css isn’t being applied when printed have you set a print stylesheet? If you are relying on the normal stylesheet to affect this div then does the stylesheet’s media attribute cover print or is it just screen?

Then why don’t you use css instead of js?

You can set up a print stylesheet to print the page as required (unless of course you have a range of print options that you haven’t mentioned yet).

All in all there is not enough information here to help solve the problem:)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.