Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

print only div jquery

Posted on 2015-01-28
3
Medium Priority
?
84 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Introduction ( All good things must come to an end ) The original MySQL API has gone away.  It was deprecated (years ago) by PHP in Version 5.5, and removed from PHP in all current releases .  As a result, the issue is upon us today.  It's time to …
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
This video teaches users how to migrate an existing Wordpress website to a new domain.
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…

670 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