1

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.

Thanks for any advice

1 Answer 1

3

Does something like this work for you:

var element = document.createElement("div")
console.log(element.outerHTML)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.