How to get the HTML for a DOM element in javascript

Viewed 199104

Imagine I have the following HTML:

<div><span><b>This is in bold</b></span></div>

I want to get the HTML for the div, including the div itself. Element.innerHTML only returns:

<span>...</span>

Any ideas? Thanks

10 Answers

old question but for newcomers that come around :

document.querySelector('div').outerHTML

Related