views:

27

answers:

1

I would like to be able to print a div with overflow:auto by clicking a link. Below is the code I am working with but it dose it on page load...

    printMe=window.open();
printMe.document.write($('.terms_and_conditions').html());
printMe.print();
printMe.close();
+1  A: 

You can wrap it in click event like:

$(function(){
  $('#element_id').click(function(){
    printMe=window.open();
    printMe.document.write($('.terms_and_conditions').html());
    printMe.print();
    printMe.close();
  });
});
Sarfraz
Awesome thank you!
CarterMan
Is there a way to simplify this to just print the `.terms_and_conditions` without opening a new window?
CarterMan