I’m trying to loop through each tab on a page in Twitter Bootstrap and print the contents of that tab when a button is clicked. In other words, if there’s 5 tabs, it loops through all of them and sends each page to the printer. The tabs are created dynamically on page load.
Right now I’ve got:
$("#idBtnPrint").click(function() {
$("#idUlTab").each(function() {
if (window.print) {
$(this).window.print();
return false;
}
});
});
But it’s not working for me. I’m not particularly strong on query (probably evident) – can anyone offer any suggestions? I don’t see any comparable code anywhere to start.
Here is a quick little jQuery plugin that will do what you are looking for. To use it, just do
$('#id').print()in your loop. If you wish to print the container that your element is in as well, use$('#id').print({container: true});The corresponding CSS for this would be (don’t forget to change the image paths for the print and cancel icons):
UPDATE
Here is an example:
HTML
Javascript