Posted injQuery / JavaScript

How to print div content using javascript?

Today, We want to share with you print div in javascript.In this post we will show you To print the data content of div in js, added content of div in a js variable after that the print button is clicked, hear for Print the content of a div element using JavaScript we will give you demo and example for implement.In this post, we will learn about jQuery Print Dynamic Content using PHP MySQL with an example.

How to print div content using javascript/jQuery?

Example 1: index.html



I am inside the div tag...

I am not inside the div tag...

JS: Print content of div


JS: Print content of div

This won't be printed

CSS Code

.hidden {

body {
  background: #edfffe;

JS Code

document.getElementById("writeNameOnPictureDownload").addEventListener("click", function() {
     var printContents = document.getElementById('pageDataDisplay').innerHTML;
     var originalContents = document.body.innerHTML;
     document.body.innerHTML = printContents;
     document.body.innerHTML = originalContents;

I hope you get an idea about div content with background image javascript.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype