Solved

print only div jquery

Posted on 2015-01-28
3
55 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
Comment Utility
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
Comment Utility
<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
Comment Utility
Found this code somewhere.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction (All good things must come to an end (http://en.wikipedia.org/wiki/All_Good_Things...)) The original MySQL API (http://php.net/manual/en/book.mysql.php) has gone away, deprecated by PHP in Version 5.5, and removed from PHP in all curre…
Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
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.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now