18

I have nested divs..in which images generate dynamically ...this is the html code ..my problem is if i click the print button the corresponding image need to be printed.

<div id="outputTemp" style="display:none">
<div id="rightoutputimgae">
<div id="rightimgId" class="rightimg"  rel="tooltip" content="
 <img src='jqe13/image/1.jpg' class='tooltip-image'/> ">
<div id="outputimageId" class="outputimage">
   <img src="jqe13/image/1.jpg" alt="Right Bottom Image"></div>
 </div>
 <ul>
 <li id="outcheckbox"><input name="outCheck" type="checkbox"></li>
<li id="outedit">
  <a href="#"><img src="jqe13/image/edit_s.PNG" alt="edit" title="Edit">
  </a></li>
<li id="outdelete"><a href="#" onclick="deleteImg(div11)">
<img src="jqe13/image/delet_c.PNG" alt="delete" title="Delete"></a></li>
<li id="outfullscreen">
<a href="#">
<img src="jqe13/image/fullscreen_c.PNG" alt="Full Screen" class="fullscreen" 
  title="Full Screen"></a></li>
 <li id="outshare">
 <a href="#"><img src="jqe13/image/share_c.PNG" alt="Share" title="Share"></a>
 <div id="menu">
 <div id="tooltip_menu">
<a href="#" class="menu_top" id="email">
<img src="jqe13/image/email.PNG" alt="Email" title="Email"></a>
<a href="#" onClick="postToFeed()" class="facebook"><img src="jqe13/image/fb.PNG" 
alt="Facebook" title="Facebook"></a>
<a href="#" id="twitter">
<img src="jqe13/image/twitter.png" alt="Twitter" title="Twitter"></a>
<a href="#" class="menu_bottom" id="save">
 <img src="jqe13/image/save.PNG" alt="Save" title="Save"></a>
 </div>
 </div>
 </li>
 <li id="outprint"><a href="#">
 <img src="jqe13/image/print.PNG" class="printMe" alt="Print" title="Print"></a>
   </li>
 </ul>
  </div>

i need to print the image when i click the print button..

how do i write jquery function to print the image..

Gautam3164
  • 28,027
  • 10
  • 58
  • 83
anu
  • 313
  • 1
  • 4
  • 14

4 Answers4

52

Try like

$('.printMe').click(function(){
     window.print();
});

or if you want to print selected area try like

$('.printMe').click(function(){
     $("#outprint").print();
});
Gautam3164
  • 28,027
  • 10
  • 58
  • 83
  • actually.. idont the whole web page to be printed..
  • Print
  • when i cick the image here..the corresponding image needs to be printed.. – anu May 09 '13 at 07:42
  • @Gautam..thanx.. i'm on it now – anu May 09 '13 at 10:06
  • hey can i do the same with multiple images – anu May 15 '13 at 04:18
  • for dynamically generated images? – anu May 15 '13 at 04:26
  • you there? i tried like using media print ..its not working to me – anu May 23 '13 at 04:09
  • Goodmorning gautam..http://jsfiddle.net/e6t2n/4/ here..and i tried like using this SO too..http://stackoverflow.com/questions/6674425/can-i-modify-this-javascript-to-print-images-from-div. – anu May 23 '13 at 04:23
  • 1
    yeah..outputimageid is the div id where i have images..can i replace the div id at block in the media print – anu May 23 '13 at 05:03
  • gautam can i use print plug ins – anu May 23 '13 at 05:04
  • http://www.jquery4u.com/plugins/10-jquery-print-page-options/ he asked me to use one of these and try – anu May 23 '13 at 05:06
  • have to look over how to put them in – anu May 23 '13 at 05:11
  • ..It worked for individual images .any way that i can print multiple images? – anu May 28 '13 at 03:43
  • 6
    this is totally not working... window.print() alone works – Mari Selvan May 19 '17 at 14:54
  • 3
    Uncaught TypeError: $(...).print is not a function – Chuck D Aug 21 '18 at 16:38
  • 2
    Same problem for me: Uncaught TypeError: $(...).print is not a function – SQL Hacks Dec 17 '18 at 12:40