How to set a print the contents of the div tag
I have a div tag on my web page which scrolls a long way to the right. I want to create a print button which the user can use to only print the contents in the div tag. Thanks for any help with开发者_开发问答 this.
Something like this
<html>
<head>
<style>
@media print {
.noprint {
display: none;
}
}
</style>
</head>
<body>
<div class="noprint">
Would not print
</div>
<div>
This would print
</div>
<div class="noprint">
Would not print
</div>
</body>
</html>
If you want a javascript based solution and you use jquery you can use this plugin: http://plugins.jquery.com/project/jqPrint
Then fire it on a click event.
$('#elementToClickOn').click(function() {
$("#divToPrint").jqprint();
});
精彩评论