Element: getHTML() method
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The getHTML()
method of the Element
interface is used to serialize an element's DOM to an HTML string.
Syntax
js
const html = element.getHTML(options)
Parameters
options
Optional-
An options object with the following optional parameters:
serializableShadowRoots
-
A boolean value that specifies whether to include serializable shadow roots. The default value is
false
. shadowRoots
-
An array of
ShadowRoot
objects to serialize. These are included regardless of whether they are marked as serializable. The default value is an empty array.
Return value
A string that represents the HTML serialization of the element.
Exceptions
None.
Specifications
Specification |
---|
HTML Standard # dom-element-gethtml |
Browser compatibility
desktop | mobile | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
getHTML |