Print the content of a div element using JavaScript (original) (raw)

Last Updated : 10 Jan, 2025

If you want to print the content of a

element using JavaScript, you can achieve this by extracting the content and then opening a new window or popup to display and print it. This method involves capturing the content of the
, creating a new window, and using the print command to print the content.

**Example 1: This example uses JavaScript window print command to print the content of div element.

html ``

Print Div Content

GeeksforGeeks

This content inside the div will be printed when you click the button.

``

**Output:

**Example 2: This example uses the JavaScript window print command to print the content of div element.

html ``

Print Div Content with Table

GeeksforGeeks

Item Description
Computer Algorithm
Microwave Infrared

The table inside the div will be printed on button click.

``

**Output:

JavaScript is best known for web page development but it is also used in a variety of non-browser environments. You can learn JavaScript from the ground up by following this JavaScript Tutorial and JavaScript Examples.