question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not able to get contents of divs with "display:none"

See original GitHub issue

Hi I want to take screen shot of a div which is hidden

this is the code I tried HTML:

<div` id="visible">
hello there!!
</div>
<div id="hidden" style="display:none">
You can't see me :P
</div>

JS:

var elem1=$("#hidden");
if(!elem1.is(":visible"))
{
elem1.show();elem1.fadeIn(1);elem1.fadeOut(1);
}
html2canvas(elem1).then(function(canvas){

$("body").append(canvas);

});

Error in Browser: **

Uncaught TypeError: Cannot read property ‘length’ of nullhtml2canvas @ html2canvas.js:941(anonymous function) @ HtmlPage.html:13

** My fiddle:https://jsfiddle.net/h39tp0Ly/2/

Please help me out with this

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:16

github_iconTop GitHub Comments

36reactions
kuraudeocommented, Jul 27, 2018

Hello, I’m working with Angular 6 and “html2canvas” to create a PDF with “jsPdf” … I wanted to take a screenshot to a hidden div and I could not do it until I ACHIEVE it

the capture is made to the div with id “html-pdf”

“HTML” `<a (click)=“download2()”> Student Card /a>

div id = “pdf” *ngIf = “test” style = “text-align: center; margin-top: 5px;”> div id = “html-pdf”>

/div /div`

“js or in angular is Typescript” `download2 () { var imgcab: string; imgcab = this.base64logo.trim ();

html2canvas (document.getElementById (‘html-pdf’), {scale:2}). Then (function (canvas) {

var img = canvas.toDataURL (“image / png”, 1);

var doc = new jsPDF ({ orientation: ‘p’, unit: ‘mm’, format: ‘letter’, });

doc.addImage (img, ‘PNG’, 2,2,212,272); doc.addImage (imgcab, ‘JPEG’, 5, 5,30,30); doc.save (‘testCanvas.pdf’); });`

And the most important thing to hide the div inside the screen.

“CSS” #pdf { overflow: hidden; height: 0; }

the code creates a pdf with the capture of the div “html-pdf” that is inside the hidden div “pdf” …

I hope you serve them

I wrote this in Spanish and it is translated, from Chile;

21reactions
kchen1025commented, Jun 7, 2018

I ran into this issue very recently, and if you want a particular div to be invisible and screenshotted, set the css properties as

height: 0% overflow:hidden

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to get display: none to work for div inside a form
In my html I have a form with a few divs inside it and each div has a button which when clicked adds...
Read more >
Lesson 5: Using Javascript to Hide and Show Content
Go to the style sheet that you created for div#clock in the previous lesson. Add the following property to the style sheet: display:...
Read more >
Hide or show elements in HTML using display property
The style display property is used to hide and show the content of HTML DOM by accessing the DOM element using JavaScript/jQuery.
Read more >
Hide and show a div - Alex Cican
In the CSS we will add two classes. One class, named .hidden , will hide the element and the other named .visible will...
Read more >
CSS Layout - The display Property - W3Schools
display : none; is commonly used with JavaScript to hide and show elements without deleting and recreating them. Take a look at our...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found