DOM Interfaces

HTMLScriptElement

Represents a script or data block and exposes script loading attributes and text content. Not every script type executes JavaScript. Scripts inserted through innerHTML do not execute merely because they were parsed. Example result: application/json.

Formal Syntax & Structure

html syntaxhtml
const element = document.getElementById('demo'); // HTMLScriptElement

Return Value

HTMLScriptElement

An existing HTML DOM object associated with the script element in this example; this interface is a type, not a function return contract.

Working Example

Example Snippethtml
<script id="demo" type="application/json">{"mode":"demo"}</script><p>  Result:  <output id="result"></output></p><script>  const e = document.getElementById('demo');  const result = value => { document.getElementById("result").textContent = String(value); };  result(e.type);</script>
HTML Reference