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.