XML technologies / HTML & XHTML / Alphabetical list of HTML and XHTML elements / script

(Excerpt from "HTML & XHTML ─ kurz & gut" by Jennifer Niederst Robbins)

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z

   

script

HTML 4.01 | HTML 5

<script> ... </script>

Places a script in the document, usually JavaScript in web documents. This element can appear any number of times in the head or body section of the document. The script itself can be inside the script element or in an external file specified by the src attribute.

Notes

If the script is supplied as the content of the script element, XHTML requires it to be enclosed in a special CDATA section, as shown in the example below.

Start/end tag

Required/required

Attributes

Global HTML 5 attributes

  • async (async="async" in XHTML 5)

    HTML 5 only. Specifies that the script should run asynchronously as soon as it is available.

  • charset="Zeichenkodierung"

    Specifies the character encoding of an external script. This does not affect the content of the script element.

  • defer (defer="defer" in XHTML)

    Specifies that the script should run only after the page has finished loading.

  • id="Text"

    XHTML and HTML 5. Gives the element a unique name.

  • language="Text"

    Deprecated. Specifies the scripting language’s name. This attribute was not standardized and is deprecated in favor of the attribute type.

  • src="URL"

    The location of the external script.

  • type="Inhaltstyp"

    Required in HTML 4.01. Optional in HTML 5 when JavaScript is used. Specifies the language of the current script. This setting takes precedence over general script settings for the document. The value is a content type, usually text/javascript.

  • xml:space="preserve"

    XHTML only. Instructs XML processors to preserve whitespace within the element.

Example (HTML 4.01 and HTML 5)

<script type="text/javascript">
... (Hier steht der JavaScript-Code) ...
</script>

Example (XHTML 1.0 and HTML 5 in XML syntax)

<script>
 // <![CDATA[
... (Hier steht der JavaScript-Code) ...
 // ]]>
</script>

 

> back to the alphabetical list of elements

   

 

 

 

back to top