Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can I get the raw HTML output from a JS HTML object?

I’ve created multiple HTML objects using

document.createElement("");

after that, I applied some modifiers like CSS, class names and onclick behaviors. How can I get the raw HTML code that is generated? My solution is creating an invisible div, adding the element as a child and call

document.getElementBy("my-invisible-div").innerHTML

to get the HTML. Is there a better way of doing this? I need it for a database export and I don’t want to have my HTML code in a string with placeholders.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks for any advice

>Solution :

Does something like this work for you:

var element = document.createElement("div")
console.log(element.outerHTML)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading