Get and Set the HTML Content of an Element

To get or set the HTML content of an element, you use the innerHTML property.

The following code shows how to query the element whose CSS class is .note and returns its HTML:

const el = document.querySelector('.note');
console.log(el.innerHTML);Code language: JavaScript (javascript)

And to set a new HTML content:

el.innerHTML  = '<p>New HTML Content</p>';Code language: HTML, XML (xml)
Was this tutorial helpful ?