Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing an individual <DIV>

Status
Not open for further replies.

tango1948

Programmer
Joined
Dec 23, 2006
Messages
111
Location
IL
Hi
I have an HTML file where each (screen)page is a <DIV>.
I can select individual pages from a dropdown list or use
NEXT and PREV buttons.
I would like to add a button to print just the <DIV> (page)currently visible. Any Tutorial links or code snippets to accomplish this much appriciated.

Thanks

David
 
Use a print style sheet, something like this:

Code:
<style type="text/css" media="print">
   div {
      display: none;
   }
   div.printMe {
      display: block;
   }
</style>

and then simply give a class of "printMe" to the div you want printed.

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Dan Thanks for the reply .
My problem is how to dynamicaly add and (after printing)remove the 'printMe' id from the div depending on which page is currently being displayed. Any ideas ?
 
Removing the "printMe" class after printing is not going to be easy to do (as you won't be able to tell when printing has finished), you'll have to use JavaScript to set the classnames on all divs before each print run.

Ask in forum216 on how to set / unset the classnames of each div - I'd go into it here, but now you've your HTML solution, it's all JS from here onwards. Note: you might want to post the code of your page (or a URL to it) to save someone asking for it.

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top