Get and set the HTML content of an element
jQuery $.html()
2015 page
This is the original page from 2015, kept at its address while the tested rewrite is in progress. The code is of its time: it ran in Internet Explorer and does not use what browsers have gained since. The rewrite replaces it here.
In short
Read or write the HTML content of an element.
The element property innerHTML is usedĀ for getting and setting the HTML content of en element in vanilla JavaScript:
var el = document.querySelector('div');
// get HTML content
console.log(el.innerHTML);
// set HTML content
el.innerHTML = '<p>Hello World!</p>'Simple as that. jQuery’s $.html() method does exactly that in the background.