innerHTML does not display Object

Asked

Viewed 71 times

0

I’m using innerHTML to fill a page, its structure goes smoothly, the problem is the variables that contain objects, they appear written in full instead of showing their values, I tried to add. text() in her name and resulted in a blank page, the most successful so far was the code below

$('#btnPrint').click(function() {
           var prtContent = document.getElementById("nome");
           console.log(prtContent);
           var WinPrint = window.open('', '', 'left=0,top=0,width=800,height=900,toolbar=0,scrollbars=0,status=0');
           WinPrint.document.body.innerHTML="<body onload='javascript:window.print();'><style>@font-face {font-family: Evogria;src: url('/files/Evogria.otf') format('opentype');}html{font-family: Evogria;}body{zoom: 100%;height:0;width:354px;margin-top:414px;bottom:0;margin-bottom:0;padding:0;margin-left:121px; margin-right:18px;font-weight:bold;}</style>"
           WinPrint.document.body.innerHTML+=`${prtContent}`;
           WinPrint.document.close();
           WinPrint.focus();
           WinPrint.print();
           document.getElementById('nome').remove()
           WinPrint.close();
        });

        }
    });

which returns an output of "[Object Htmltablecellelement]", someone can tell if the variable has stopped pulling the object, or if there’s something wrong with the way I’m trying to present it?

  • Try to replace the line WinPrint.document.body.innerHTML+=${prtContent}; for WinPrint.document.body.append(prtContent)

  • It worked, thank you very much!!

1 answer

2


When you give the append to prtContent, use prtContent.outerHtml

WinPrint.document.body.innerHTML += prtContent.outerHTML;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.