How to get the HTML for a DOM element in JavaScript?

Spread the love

To get the HTML for a DOM element in JavaScript, we use the outerHTML property.

For instance, we write

const el = document.getElementById("foo");
console.log(el.outerHTML);

to get the element with getElementById.

And then we get the code for the element with the outerHTML property.

Leave a Reply

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