Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

print only div jquery

Posted on 2015-01-28
3
Medium Priority
?
93 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 51

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
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.
Suggested Courses

916 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