Solved

print only div jquery

Posted on 2015-01-28
3
61 Views
Last Modified: 2015-06-17
Can you guys help me with this, I think this should be easy and I think I am close.  I want to print just a div, the div's ID is not exactly FormControl but has FormControl in it.  Firebug doesnt like the line with the print statement in it.  It say "TypeError: $(...).print is not a function ".

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>

$infopathdiv = $('div[id$="FormControl"]');

$(document).ready( function() {
  $("#printbutton").click(function(){$("#infopathdiv").print();});
});
</script>

<input id="printbutton" type="button" value="Print this page"/>

Open in new window

0
Comment
Question by:Demosthenes
  • 2
3 Comments
 
LVL 50

Expert Comment

by:Steve Bink
ID: 40577857
Printing is not part of core jQuery, though some people have made plugins to do what you want.  Take a look at http://www.bennadel.com/blog/1591-ask-ben-print-part-of-a-web-page-with-jquery.htm, or google "jquery print".
0
 

Accepted Solution

by:
Demosthenes earned 0 total points
ID: 40826357
<input type="button" onclick="printDiv('printableArea')" value="Print This Notice" />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
function printDiv(divName) {


     //window.alert(printablearea);

     //var printContents = document.getElementById(divName).innerHTML;

     var originalContents = document.body.innerHTML;

     var printablearea = $('div[id*="WebPartWPQ2"]').html();

     $('body').html(printablearea);

     window.print();

     document.body.innerHTML = originalContents;
}
</script>
0
 

Author Closing Comment

by:Demosthenes
ID: 40834211
Found this code somewhere.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question