Expand your HTML skills through an MDN Fellowship - Apply by April 1 http://mzl.la/MDNFellowship

mozilla

Revision 45687 of <script>

  • Revision slug: HTML/Element/Script
  • Revision title: script
  • Revision id: 45687
  • Created:
  • Creator: vidyadhara
  • Is current revision? No
  • Comment 72 words added

Revision Content

Summary

The script element is used to embed or reference an executable script within an HTML or XHTML document.

Attributes

src
This attribute specifies the URI of an external script; this can be used as an alternative to embedding a script directly within a document. script elements with an src attribute specified should not have a script embedded within its tags.
type
This attribute identifies the scripting language of code embedded within a script element or referenced via the element’s src attribute. This is specified as a MIME type; examples of supported MIME types include text/javascript, text/ecmascript, application/javascript, and application/ecmascript. This attribute must be specified per various HTML and XHTML DTDs.
language {{ Deprecated_inline() }}
Like the type attribute, this attribute identifies the scripting language in use. Unlike the type attribute, however, this attribute’s possible values were never standardized. The type attribute should be used instead.
defer {{ fx_minversion_inline("3.1") }}
This Boolean attribute is set (to the value defer) to indicate to a browser that it may continue parsing and rendering a document without waiting for a script to be executed. Since this feature is optional, authors should not assume that the script’s execution will actually be deferred.

Example

<html>
<head>
<script type="text/javascript" src="/clientsidescripts/behaviors.js"></script>
</head>
<body ..>
</body>
</html>

For some reason the script element does not allow tag termination within the first part of the tag. like <script ..... />

It requires the closing tag to lie outside separately. like this

<script ...> </script>

Otherwise it does not work.

Should this be called a block element. I dont think you can include it inside body. It is just another element.

Revision Source

<h3 id="Summary" name="Summary">Summary</h3>
<p>The <code>script</code> element is used to embed or reference an executable script within an <abbr>HTML</abbr> or <abbr>XHTML</abbr> document.</p>
<ul> <li>Element Type: <a href="/en/HTML/Block-level_elements" title="en/HTML/Block-level_elements">block‐level</a></li> <li>Allowed Content: script content</li>
</ul>
<h3 id="Attributes" name="Attributes">Attributes</h3>
<dl> <dt style="margin-top: 1em;"><code>src</code></dt> <dd>This attribute specifies the <abbr>URI</abbr> of an external script; this can be used as an alternative to embedding a script directly within a document. <code>script</code> elements with an <code>src</code> attribute specified should not have a script embedded within its tags.</dd></dl><dl> <dt style="margin-top: 1em;"><code>type</code></dt> <dd>This attribute identifies the scripting language of code embedded within a <code>script</code> element or referenced via the element’s <code>src</code> attribute. This is specified as a <abbr>MIME type; examples of supported <abbr>MIME types include <code>text/javascript</code>, <code>text/ecmascript</code>, <code>application/javascript</code>, and <code>application/ecmascript</code>. This attribute must be specified per various <abbr>HTML and <abbr>XHTML <abbr>DTDs. </abbr></abbr></abbr></abbr></abbr></dd><dt style="margin-top: 1em;"><code>language</code> {{ Deprecated_inline() }} </dt> <dd>Like the <code>type</code> attribute, this attribute identifies the scripting language in use. Unlike the <code>type</code> attribute, however, this attribute’s possible values were never standardized. The <code>type</code> attribute should be used instead.</dd> <dt style="margin-top: 1em;"><code>defer</code> {{ fx_minversion_inline("3.1") }}</dt> <dd>This Boolean attribute is set (to the value <code>defer</code>) to indicate to a browser that it <strong>may</strong> continue parsing and rendering a document without waiting for a script to be executed. Since this feature is optional, authors should not assume that the script’s execution will actually be deferred.</dd> </dl>
<p><strong>Example</strong></p>
<pre>&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript" src="/clientsidescripts/behaviors.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body ..&gt;
</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>For some reason the script element does not allow tag termination within the first part of the tag. like &lt;script ..... /&gt;</p>
<p>It requires the closing tag to lie outside separately. like this </p>
<p>&lt;script ...&gt; &lt;/script&gt;</p>
<p>Otherwise it does not work.</p>
<p>Should this be called a block element. I dont think you can include it inside body. It is just another element.</p>
Revert to this revision