Skip to content
Advertisement

Difference between HTML template content and innerHTML

Say I have an HTML <template> tag that I define and select as follows:

JavaScript

What is the difference between these properties of the template:

JavaScript

Advertisement

Answer

Contrary to innerHTML, content returns a document fragment, and so you get immediate access to the DOM without an intermediate conversion to and from a string.

Here is the difference in use:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement