Annotation of html5/spec-author-view/scripting-1.html, revision 1.21

1.9       mike        1: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
                      2: <!DOCTYPE html>
                      3: <!-- when publishing, change bits marked ZZZ --><html lang="en-US-x-Hixie" class="split chapter"><head><title>4.3 Scripting &#8212; HTML5 (Author Edition)</title><script src="link-fixup.js"></script><link href="whatwg.css" rel="stylesheet"><style type="text/css">
                      4:    pre { margin-left: 2em; white-space: pre-wrap; }
                      5:    h2 { margin: 3em 0 1em 0; }
                      6:    h3 { margin: 2.5em 0 1em 0; }
                      7:    h4 { margin: 2.5em 0 0.75em 0; }
                      8:    h5, h6 { margin: 2.5em 0 1em; }
                      9:    h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
                     10:    h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
                     11:    p { margin: 1em 0; }
                     12:    hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
                     13:    dl, dd { margin-top: 0; margin-bottom: 0; }
                     14:    dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
                     15:    dt + dt { margin-top: 0; }
                     16:    dd dt { margin-top: 0.25em; margin-bottom: 0; }
                     17:    dd p { margin-top: 0; }
                     18:    dd dl + p { margin-top: 1em; }
                     19:    dd table + p { margin-top: 1em; }
                     20:    p + * > li, dd li { margin: 1em 0; }
                     21:    dt, dfn { font-weight: bold; font-style: normal; }
                     22:    dt dfn { font-style: italic; }
                     23:    pre, code { font-size: inherit; font-family: monospace; font-variant: normal; }
                     24:    pre strong { color: black; font: inherit; font-weight: bold; background: yellow; }
                     25:    pre em { font-weight: bolder; font-style: normal; }
                     26:    @media screen { code { color: orangered; } code :link, code :visited { color: inherit; } }
                     27:    var sub { vertical-align: bottom; font-size: smaller; position: relative; top: 0.1em; }
                     28:    table { border-collapse: collapse; border-style: hidden hidden none hidden; }
                     29:    table thead { border-bottom: solid; }
                     30:    table tbody th:first-child { border-left: solid; }
                     31:    table tbody th { text-align: left; }
                     32:    table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
                     33:    blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
                     34: 
                     35:    .bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
                     36:    .matrix, .matrix td { border: none; text-align: right; }
                     37:    .matrix { margin-left: 2em; }
                     38:    .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
                     39:    .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
                     40:    .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
                     41: 
                     42:    .toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
                     43:    img.extra { float: right; }
                     44:    pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
                     45:    pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
                     46:    pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
                     47:    pre.css:first-line { color: #AAAA50; }
1.17      mike       48:    dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #DDFFDD; }
1.9       mike       49:    hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
                     50:    dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
                     51:    dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
                     52:    dl.domintro dd p { margin: 0.5em 0; }
                     53:    dl.switch { padding-left: 2em; }
                     54:    dl.switch > dt { text-indent: -1.5em; }
                     55:    dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
                     56:    dl.triple { padding: 0 0 0 1em; }
                     57:    dl.triple dt, dl.triple dd { margin: 0; display: inline }
                     58:    dl.triple dt:after { content: ':'; }
                     59:    dl.triple dd:after { content: '\A'; white-space: pre; }
                     60:    .diff-old { text-decoration: line-through; color: silver; background: transparent; }
                     61:    .diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
                     62:    a .diff-new { border-bottom: 1px blue solid; }
                     63: 
                     64:    h2 { page-break-before: always; }
                     65:    h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
                     66:    h1 + h2, hr + h2.no-toc { page-break-before: auto; }
                     67: 
                     68:    p > span:not([title=""]):not([class="XXX"]):not([class="impl"]), li > span:not([title=""]):not([class="XXX"]):not([class="impl"]) { border-bottom: solid #9999CC; }
                     69: 
                     70:    div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
                     71:    div.head p { margin: 0; }
                     72:    div.head h1 { margin: 0; }
                     73:    div.head .logo { float: right; margin: 0 1em; }
                     74:    div.head .logo img { border: none } /* remove border from top image */
                     75:    div.head dl { margin: 1em 0; }
                     76:    div.head p.copyright, div.head p.alt { font-size: x-small; font-style: oblique; margin: 0; }
                     77: 
                     78:    body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
                     79:    body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
                     80:    body > .toc > li > * { margin-bottom: 0.5em; }
                     81:    body > .toc > li > * > li > * { margin-bottom: 0.25em; }
                     82:    .toc, .toc li { list-style: none; }
                     83: 
                     84:    .brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
                     85:    .brief li { margin: 0; padding: 0; }
                     86:    .brief li p { margin: 0; padding: 0; }
                     87: 
                     88:    .category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
                     89:    .category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
                     90:    .category-list li { display: inline; }
                     91:    .category-list li:not(:last-child)::after { content: ', '; }
                     92:    .category-list li > span, .category-list li > a { text-transform: lowercase; }
                     93:    .category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
                     94: 
                     95:    .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
                     96:    .XXX > :first-child { margin-top: 0; }
                     97:    p .XXX { line-height: 3em; }
                     98:    .annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
                     99:    .annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
                    100:    .annotation :link, .annotation :visited { color: inherit; }
                    101:    .annotation :link:hover, .annotation :visited:hover { background: transparent; }
                    102:    .annotation span { border: none ! important; }
                    103:    .note { color: green; background: transparent; font-family: sans-serif; }
                    104:    .warning { color: red; background: transparent; }
                    105:    .note, .warning { font-weight: bolder; font-style: italic; }
                    106:    p.note, div.note { padding: 0.5em 2em; }
                    107:    span.note { padding: 0 2em; }
                    108:    .note p:first-child, .warning p:first-child { margin-top: 0; }
                    109:    .note p:last-child, .warning p:last-child { margin-bottom: 0; }
                    110:    .warning:before { font-style: normal; }
                    111:    p.note:before { content: 'Note: '; }
                    112:    p.warning:before { content: '\26A0 Warning! '; }
                    113: 
                    114:    .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
                    115:    .bookkeeping { font-size: 0.8em; margin: 2em 0; }
                    116:    .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
                    117: 
                    118:    h4 { position: relative; z-index: 3; }
                    119:    h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
                    120:    .element {
                    121:      background: #EEEEFF;
                    122:      color: black;
                    123:      margin: 0 0 1em 0.15em;
                    124:      padding: 0 1em 0.25em 0.75em;
                    125:      border-left: solid #9999FF 0.25em;
                    126:      position: relative;
                    127:      z-index: 1;
                    128:    }
                    129:    .element:before {
                    130:      position: absolute;
                    131:      z-index: 2;
                    132:      top: 0;
                    133:      left: -1.15em;
                    134:      height: 2em;
                    135:      width: 0.9em;
                    136:      background: #EEEEFF;
                    137:      content: ' ';
                    138:      border-style: none none solid solid;
                    139:      border-color: #9999FF;
                    140:      border-width: 0.25em;
                    141:    }
                    142: 
                    143:    .example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
                    144:    td > .example:only-child { margin: 0 0 0 0.1em; }
                    145: 
                    146:    .tall-and-narrow {
                    147:      font-size: 0.6em;
                    148:      column-width: 25em;
                    149:      column-gap: 1em;
                    150:      -moz-column-width: 25em;
                    151:      -moz-column-gap: 1em;
                    152:      -webkit-column-width: 25em;
                    153:      -webkit-column-gap: 1em;
                    154:    }
                    155: 
                    156:    ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
                    157:    ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
                    158:    ul.domTree li li { list-style: none; }
                    159:    ul.domTree li:first-child::before { position: absolute; top: 0; height: 0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
                    160:    ul.domTree li:not(:last-child)::after { position: absolute; top: 0; bottom: -0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
                    161:    ul.domTree span { font-style: italic; font-family: serif; }
                    162:    ul.domTree .t1 code { color: purple; font-weight: bold; }
                    163:    ul.domTree .t2 { font-style: normal; font-family: monospace; }
                    164:    ul.domTree .t2 .name { color: black; font-weight: bold; }
                    165:    ul.domTree .t2 .value { color: blue; font-weight: normal; }
                    166:    ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
                    167:    ul.domTree .t7 code, .domTree .t8 code { color: green; }
                    168:    ul.domTree .t10 code { color: teal; }
                    169: 
1.13      mike      170:    body.dfnEnabled dfn { cursor: pointer; }
                    171:    .dfnPanel {
                    172:      display: inline;
                    173:      position: absolute;
                    174:      z-index: 10;
                    175:      height: auto;
                    176:      width: auto;
                    177:      padding: 0.5em 0.75em;
                    178:      font: small sans-serif, Droid Sans Fallback;
                    179:      background: #DDDDDD;
                    180:      color: black;
                    181:      border: outset 0.2em;
                    182:    }
                    183:    .dfnPanel * { margin: 0; padding: 0; font: inherit; text-indent: 0; }
                    184:    .dfnPanel :link, .dfnPanel :visited { color: black; }
                    185:    .dfnPanel p { font-weight: bolder; }
                    186:    .dfnPanel * + p { margin-top: 0.25em; }
                    187:    .dfnPanel li { list-style-position: inside; }
                    188: 
1.9       mike      189:    #configUI { position: absolute; z-index: 20; top: 10em; right: 1em; width: 11em; font-size: small; }
                    190:    #configUI p { margin: 0.5em 0; padding: 0.3em; background: #EEEEEE; color: black; border: inset thin; }
                    191:    #configUI p label { display: block; }
                    192:    #configUI #updateUI, #configUI .loginUI { text-align: center; }
                    193:    #configUI input[type=button] { display: block; margin: auto; }
                    194:   </style><style type="text/css">
                    195: 
                    196:    .applies thead th > * { display: block; }
                    197:    .applies thead code { display: block; }
                    198:    .applies tbody th { whitespace: nowrap; }
                    199:    .applies td { text-align: center; }
                    200:    .applies .yes { background: yellow; }
                    201: 
                    202:    .matrix, .matrix td { border: none; text-align: right; }
                    203:    .matrix { margin-left: 2em; }
                    204: 
                    205:    .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
                    206:    .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
                    207:    .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
                    208: 
                    209:    #table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
                    210:    #table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
                    211:    #table-example-1 caption { padding-bottom: 0.5em; }
                    212:    #table-example-1 thead, #table-example-1 tbody { border: none; }
                    213:    #table-example-1 th, #table-example-1 td { border: solid thin; }
                    214:    #table-example-1 th { font-weight: normal; }
                    215:    #table-example-1 td { border-style: none solid; vertical-align: top; }
                    216:    #table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
                    217:    #table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
                    218:    #table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
                    219:    #table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
                    220:    #table-example-1 tbody td:first-child::after { content: leader(". "); }
                    221:    #table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
                    222:    #table-example-1 tbody td:first-child + td { width: 10em; }
                    223:    #table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
                    224:    #table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
                    225: 
                    226:    .apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
                    227:    .apple-table-examples * { font-family: "Times", serif; }
                    228:    .apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
                    229:    .apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
                    230:    .apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
                    231:    .apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
                    232:    .apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
                    233:    .apple-table-examples td { text-align: right; vertical-align: top; }
                    234:    .apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
1.11      mike      235:    .apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
                    236:    .apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
                    237:    .apple-table-examples sup { line-height: 0; }
                    238: 
1.12      mike      239:    .details-example img { vertical-align: top; }
                    240: 
1.18      mike      241:   </style><style type="text/css">
1.21    ! mike      242:    .domintro:before { display: table; margin: -1em -0.5em -0.5em auto; width: auto; content: 'This box is non-normative. Implementation requirements are given below this box.'; color: black; font-style: italic; border: solid 2px; background: white; padding: 0 0.25em; }
        !           243:   </style><link href="data:text/css," id="complete" rel="stylesheet" title="Complete specification"><link href="data:text/css,.impl%20%7B%20display:%20none;%20%7D%0Ahtml%20%7B%20border:%20solid%20yellow;%20%7D%20.domintro:before%20%7B%20display:%20none;%20%7D" id="author" rel="alternate stylesheet" title="Author documentation only"><link href="data:text/css,.impl%20%7B%20background:%20%23FFEEEE;%20%7D%20.domintro:before%20%7B%20background:%20%23FFEEEE;%20%7D" id="highlight" rel="alternate stylesheet" title="Highlight implementation requirements"><script type="text/javascript">
1.11      mike      244:    function getCookie(name) {
                    245:      var params = location.search.substr(1).split("&");
                    246:      for (var index = 0; index < params.length; index++) {
                    247:        if (params[index] == name)
                    248:          return "1";
                    249:        var data = params[index].split("=");
                    250:        if (data[0] == name)
                    251:          return unescape(data[1]);
                    252:      }
                    253:      var cookies = document.cookie.split("; ");
                    254:      for (var index = 0; index < cookies.length; index++) {
                    255:        var data = cookies[index].split("=");
                    256:        if (data[0] == name)
                    257:          return unescape(data[1]);
                    258:      }
                    259:      return null;
                    260:    }
                    261:    function load(script) {
                    262:      var e = document.createElement('script');
                    263:      e.setAttribute('src', 'http://www.whatwg.org/specs/web-apps/current-work/' + script + '?' + encodeURIComponent(location) + '&' + encodeURIComponent(document.referrer));
                    264:      document.body.appendChild(e);
                    265:    }
                    266:    function init() {
                    267:      if (location.search == '?slow-browser')
                    268:        return;
                    269:      var configUI = document.createElement('div');
                    270:      configUI.id = 'configUI';
                    271:      document.body.appendChild(configUI);
                    272:      // load('reviewer.js'); // would need cross-site XHR
                    273:      if (document.getElementById('head'))
                    274:        load('toc.js');
                    275:      
                    276:      // load('updater.js'); // would need cross-site XHR
1.12      mike      277:      load('dfn.js'); // doesn't support split-out specs, but, oh well.
1.11      mike      278:      // load('status.js'); // would need cross-site XHR
                    279:      if (getCookie('profile') == '1')
                    280:        document.getElementsByTagName('h2')[0].textContent += '; load: ' + (new Date() - loadTimer) + 'ms';
                    281:      fixBrokenLink();
                    282:    }
1.15      mike      283:   </script><link href="http://www.w3.org/StyleSheets/TR/W3C-WD" rel="stylesheet" type="text/css"><link href="semantics.html" title="4 The elements of HTML" rel="prev">
1.11      mike      284:   <link href="Overview.html#contents" title="Table of contents" rel="index">
                    285:   <link href="sections.html" title="4.4 Sections" rel="next">
                    286:   </head><body onload="fixBrokenLink(); init()"><div class="head" id="head">
                    287:    <p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
                    288:    <h1>HTML5 (Author Edition)</h1>
                    289:    </div><div>
                    290:    <a href="semantics.html">&#8592; 4 The elements of HTML</a> &#8211;
                    291:    <a href="Overview.html#contents">Table of contents</a> &#8211;
                    292:    <a href="sections.html">4.4 Sections &#8594;</a>
                    293:   <ol class="toc"><li><ol><li><a href="scripting-1.html#scripting-1"><span class="secno">4.3 </span>Scripting</a>
                    294:     <ol><li><a href="scripting-1.html#script"><span class="secno">4.3.1 </span>The <code>script</code> element</a>
                    295:       <ol><li><a href="scripting-1.html#scriptingLanguages"><span class="secno">4.3.1.1 </span>Scripting languages</a></li><li><a href="scripting-1.html#restrictions-for-contents-of-script-elements"><span class="secno">4.3.1.2 </span>Restrictions for contents of <code>script</code> elements</a></li><li><a href="scripting-1.html#inline-documentation-for-external-scripts"><span class="secno">4.3.1.3 </span>Inline documentation for external scripts</a></li></ol></li><li><a href="scripting-1.html#the-noscript-element"><span class="secno">4.3.2 </span>The <code>noscript</code> element</a></li></ol></li></ol></li></ol></div>
                    296: 
                    297:   <h3 id="scripting-1"><span class="secno">4.3 </span>Scripting</h3><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><p>Scripts allow authors to add interactivity to their documents.</p><p>Authors are encouraged to use declarative alternatives to
                    298:   scripting where possible, as declarative mechanisms are often more
                    299:   maintainable, and many users disable scripting.</p><div class="example">
                    300:    <p>For example, instead of using script to show or hide a section
                    301:    to show more details, the <code><a href="interactive-elements.html#the-details-element">details</a></code> element could be
                    302:    used.</p>
                    303:   </div><p>Authors are also encouraged to make their applications degrade
                    304:   gracefully in the absence of scripting support.</p><div class="example">
                    305:    <p>For example, if an author provides a link in a table header to
                    306:    dynamically resort the table, the link could also be made to
                    307:    function without scripts by requesting the sorted table from the
                    308:    server.</p>
                    309:   </div><h4 id="script"><span class="secno">4.3.1 </span>The <dfn><code>script</code></dfn> element</h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><dl class="element"><dt>Categories</dt>
                    310:    <dd><a href="content-models.html#metadata-content">Metadata content</a>.</dd>
                    311:    <dd><a href="content-models.html#flow-content">Flow content</a>.</dd>
                    312:    <dd><a href="content-models.html#phrasing-content">Phrasing content</a>.</dd>
                    313:    <dt>Contexts in which this element may be used:</dt>
                    314:    <dd>Where <a href="content-models.html#metadata-content">metadata content</a> is expected.</dd>
                    315:    <dd>Where <a href="content-models.html#phrasing-content">phrasing content</a> is expected.</dd>
                    316:    <dt>Content model:</dt>
                    317:    <dd>If there is no <code title="attr-script-src"><a href="#attr-script-src">src</a></code>
                    318:    attribute, depends on the value of the <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute, but must match
                    319:    <a href="#restrictions-for-contents-of-script-elements">script content restrictions</a>.</dd>
                    320:    <dd>If there <em>is</em> a <code title="attr-script-src"><a href="#attr-script-src">src</a></code>
                    321:    attribute, the element must be either empty or contain only
                    322:    <a href="#inline-documentation-for-external-scripts">script documentation</a> that also matches <a href="#restrictions-for-contents-of-script-elements">script
                    323:    content restrictions</a>.</dd>
                    324:    <dt>Content attributes:</dt>
                    325:    <dd><a href="elements.html#global-attributes">Global attributes</a></dd>
                    326:    <dd><code title="attr-script-src"><a href="#attr-script-src">src</a></code></dd>
                    327:    <dd><code title="attr-script-async"><a href="#attr-script-async">async</a></code></dd>
                    328:    <dd><code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code></dd>
                    329:    <dd><code title="attr-script-type"><a href="#attr-script-type">type</a></code></dd>
                    330:    <dd><code title="attr-script-charset"><a href="#attr-script-charset">charset</a></code></dd>
                    331:    <dt>DOM interface:</dt>
                    332:    <dd>
                    333: <pre class="idl">interface <dfn id="htmlscriptelement">HTMLScriptElement</dfn> : <a href="elements.html#htmlelement">HTMLElement</a> {
                    334:            attribute DOMString <a href="#dom-script-src" title="dom-script-src">src</a>;
                    335:            attribute boolean <a href="#dom-script-async" title="dom-script-async">async</a>;
                    336:            attribute boolean <a href="#dom-script-defer" title="dom-script-defer">defer</a>;
                    337:            attribute DOMString <a href="#dom-script-type" title="dom-script-type">type</a>;
                    338:            attribute DOMString <a href="#dom-script-charset" title="dom-script-charset">charset</a>;
                    339:            attribute DOMString <a href="#dom-script-text" title="dom-script-text">text</a>;
                    340: };</pre>
                    341:    </dd>
                    342:   </dl><p>The <code><a href="#script">script</a></code> element allows authors to include dynamic
                    343:   script and data blocks in their documents. The element does not
                    344:   <a href="#represents" title="represents">represent</a> content for the user.</p><p>When used to include dynamic scripts, the scripts may either be
                    345:   embedded inline or may be imported from an external file using the
                    346:   <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute. If the language
                    347:   is not that described by "<code title="">text/javascript</code>",
                    348:   then the <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute must
                    349:   be present, as described below.</p><p>When used to include data blocks, the data must be embedded
                    350:   inline, the format of the data must be given using the <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute, and the <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute must not be
                    351:   specified.</p><p>The <dfn id="attr-script-type" title="attr-script-type"><code>type</code></dfn>
                    352:   attribute gives the language of the script or format of the data. If
                    353:   the attribute is present, its value must be a <a href="infrastructure.html#valid-mime-type">valid MIME
1.12      mike      354:   type</a>. The <code title="">charset</code> parameter must not be
1.14      mike      355:   specified. The default, which is used if the attribute is absent,
                    356:   is "<code title="">text/javascript</code>".</p><p>The <dfn id="attr-script-src" title="attr-script-src"><code>src</code></dfn>
1.11      mike      357:   attribute, if specified, gives the address of the external script
1.19      mike      358:   resource to use. The value of the attribute must be a <a href="urls.html#valid-non-empty-url">valid
                    359:   non-empty URL</a> identifying a script resource of the type given
                    360:   by the <code title="attr-script-type"><a href="#attr-script-type">type</a></code> attribute, if the
1.11      mike      361:   attribute is present, or of the type "<code title="">text/javascript</code>", if the attribute is absent. A
                    362:   resource is a script resource of a given type if that type
                    363:   identifies a scripting language and the resource conforms with the
                    364:   requirements of that language's specification.</p><p>The <dfn id="attr-script-charset" title="attr-script-charset"><code>charset</code></dfn>
                    365:   attribute gives the character encoding of the external script
                    366:   resource. The attribute must not be specified if the <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute is not present. If the
                    367:   attribute is set, its value must be a valid character encoding name,
                    368:   must be an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the
                    369:   <a href="infrastructure.html#preferred-mime-name">preferred MIME name</a> for that encoding, and must match
                    370:   the encoding given in the <code title="">charset</code> parameter of
                    371:   the <a href="#content-type" title="Content-Type">Content-Type metadata</a> of the
                    372:   external file, if any. <a href="references.html#refsIANACHARSET">[IANACHARSET]</a></p><p>The <dfn id="attr-script-async" title="attr-script-async"><code>async</code></dfn> and
                    373:   <dfn id="attr-script-defer" title="attr-script-defer"><code>defer</code></dfn> attributes
                    374:   are <a href="common-microsyntaxes.html#boolean-attribute" title="boolean attribute">boolean attributes</a> that
                    375:   indicate how the script should be executed.</p><p>There are three possible modes that can be selected using these
                    376:   attributes. If the <code title="attr-script-async"><a href="#attr-script-async">async</a></code>
                    377:   attribute is present, then the script will be executed
                    378:   asynchronously, as soon as it is available. If the <code title="attr-script-async"><a href="#attr-script-async">async</a></code> attribute is not present but
                    379:   the <code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code> attribute is
                    380:   present, then the script is executed when the page has finished
                    381:   parsing. If neither attribute is present, then the script is
                    382:   fetched and executed immediately, before the user agent continues
1.20      mike      383:   parsing the page.</p><p class="note">The exact processing details for these attributes
                    384:   are, for mostly historical reasons, somewhat non-trivial, involving
                    385:   a number of aspects of HTML. The implementation requirements are
                    386:   therefore by necessity scattered throughout the specification. The
                    387:   algorithms below (in this section) describe the core of this
                    388:   processing, but these algorithms reference and are referenced by the
                    389:   parsing rules for <code><a href="#script">script</a></code> <a href="#scriptTag">start</a>
                    390:   and <a href="#scriptEndTag">end</a> tags in HTML, <a href="#scriptForeignEndTag">in foreign content</a>, and <a href="#scriptTagXML">in XML</a>, the rules for the <code title="dom-document-write"><a href="#dom-document-write">document.write()</a></code> method, the
                    391:   handling of <a href="webappapis.html#scripting">scripting</a>, etc.</p><p>The <code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code> attribute may be
1.11      mike      392:   specified even if the <code title="attr-script-async"><a href="#attr-script-async">async</a></code>
                    393:   attribute is specified, to cause legacy Web browsers that only
                    394:   support <code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code> (and not <code title="attr-script-async"><a href="#attr-script-async">async</a></code>) to fall back to the <code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code> behavior instead of the
                    395:   synchronous blocking behavior that is the default.</p><p>If one or both of the <code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code> and <code title="attr-script-async"><a href="#attr-script-async">async</a></code> attributes are specified, the
                    396:   <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute must also be
                    397:   specified.</p><p>Changing the <code title="attr-script-src"><a href="#attr-script-src">src</a></code>, <code title="attr-script-type"><a href="#attr-script-type">type</a></code>, <code title="attr-script-charset"><a href="#attr-script-charset">charset</a></code>, <code title="attr-script-async"><a href="#attr-script-async">async</a></code>, and <code title="attr-script-defer"><a href="#attr-script-defer">defer</a></code> attributes dynamically has no
1.12      mike      398:   direct effect; these attribute are only used at specific times
                    399:   described below.</p><!-- by implication, changes to the base URL
                    400:   also have no effect --><dl class="domintro"><dt><var title="">script</var> . <code title="dom-script-text"><a href="#dom-script-text">text</a></code> [ = <var title="">value</var> ]</dt>
1.11      mike      401: 
                    402:    <dd>
                    403: 
                    404:     <p>Returns the contents of the element, ignoring child nodes that
                    405:     aren't <a href="infrastructure.html#text-node" title="text node">text nodes</a>.</p>
                    406: 
                    407:     <p>Can be set, to replace the element's children with the given
                    408:     value.</p>
                    409: 
                    410:    </dd>
                    411: 
                    412:   </dl><p class="note">When inserted using the <code title="dom-document-write"><a href="#dom-document-write">document.write()</a></code> method,
                    413:   <code><a href="#script">script</a></code> elements execute (typically synchronously), but
                    414:   when inserted using <code title="dom-innerHTML"><a href="apis-in-html-documents.html#dom-innerhtml">innerHTML</a></code> and <code title="dom-outerHTML"><a href="apis-in-html-documents.html#dom-outerhtml">outerHTML</a></code> attributes, they do not
                    415:   execute at all.</p><div class="example">
                    416: 
                    417:    <p>In this example, two <code><a href="#script">script</a></code> elements are used. One
                    418:    embeds an external script, and the other includes some data.</p>
                    419: 
                    420:    <pre>&lt;script src="game-engine.js"&gt;&lt;/script&gt;
                    421: &lt;script type="text/x-game-map"&gt;
                    422: ........U.........e
                    423: o............A....e
                    424: .....A.....AAA....e
                    425: .A..AAA...AAAAA...e
                    426: &lt;/script&gt;</pre>
                    427: 
                    428:    <p>The data in this case might be used by the script to generate
                    429:    the map of a video game. The data doesn't have to be used that way,
                    430:    though; maybe the map data is actually embedded in other parts of
                    431:    the page's markup, and the data block here is just used by the
                    432:    site's search engine to help users who are looking for particular
                    433:    features in their game maps.</p>
                    434: 
                    435:   </div><div class="example">
                    436: 
                    437:    <p>The following sample shows how a script element can be used to
                    438:    define a function that is then used by other parts of the
                    439:    document. It also shows how a <code><a href="#script">script</a></code> element can be
                    440:    used to invoke script while the document is being parsed, in this
                    441:    case to initialize the form's output.</p>
                    442: 
                    443:    <pre>&lt;script&gt;
                    444:  function calculate(form) {
                    445:    var price = 52000;
                    446:    if (form.elements.brakes.checked)
                    447:      price += 1000;
                    448:    if (form.elements.radio.checked)
                    449:      price += 2500;
                    450:    if (form.elements.turbo.checked)
                    451:      price += 5000;
                    452:    if (form.elements.sticker.checked)
                    453:      price += 250;
                    454:    form.elements.result.value = price;
                    455:  }
                    456: &lt;/script&gt;
                    457: &lt;form name="pricecalc" onsubmit="return false"&gt;
                    458:  &lt;fieldset&gt;
                    459:   &lt;legend&gt;Work out the price of your car&lt;/legend&gt;
                    460:   &lt;p&gt;Base cost: &#163;52000.&lt;/p&gt;
                    461:   &lt;p&gt;Select additional options:&lt;/p&gt;
                    462:   &lt;ul&gt;
                    463:    &lt;li&gt;&lt;label&gt;&lt;input type=checkbox name=brakes&gt; Ceramic brakes (&#163;1000)&lt;/label&gt;&lt;/li&gt;
                    464:    &lt;li&gt;&lt;label&gt;&lt;input type=checkbox name=radio&gt; Satellite radio (&#163;2500)&lt;/label&gt;&lt;/li&gt;
                    465:    &lt;li&gt;&lt;label&gt;&lt;input type=checkbox name=turbo&gt; Turbo charger (&#163;5000)&lt;/label&gt;&lt;/li&gt;
                    466:    &lt;li&gt;&lt;label&gt;&lt;input type=checkbox name=sticker&gt; "XZ" sticker (&#163;250)&lt;/label&gt;&lt;/li&gt;
                    467:   &lt;/ul&gt;
                    468:   &lt;p&gt;Total: &#163;&lt;output name=result onformchange="calculate(form)"&gt;&lt;/output&gt;&lt;/p&gt;
                    469:  &lt;/fieldset&gt;
                    470:  &lt;script&gt;
                    471:   document.forms.pricecalc.dispatchFormChange();
                    472:  &lt;/script&gt;
                    473: &lt;/form&gt;</pre>
                    474: 
                    475:   </div><h5 id="scriptingLanguages"><span class="secno">4.3.1.1 </span>Scripting languages</h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><p>The following lists some <a href="infrastructure.html#mime-type">MIME type</a> strings and the
                    476:   languages to which they refer:</p><dl><dt>"<code>application/ecmascript</code>"</dt>
                    477:    <dt>"<code>application/javascript</code>"</dt>
                    478:    <dt>"<code>application/x-ecmascript</code>"</dt>
                    479:    <dt>"<code>application/x-javascript</code>"</dt>
                    480:    <dt>"<code>text/ecmascript</code>"</dt>
                    481:    <dt>"<code>text/javascript</code>"</dt>
                    482:    <dt>"<code>text/javascript1.0</code>"</dt>
                    483:    <dt>"<code>text/javascript1.1</code>"</dt>
                    484:    <dt>"<code>text/javascript1.2</code>"</dt>
                    485:    <dt>"<code>text/javascript1.3</code>"</dt>
                    486:    <dt>"<code>text/javascript1.4</code>"</dt>
                    487:    <dt>"<code>text/javascript1.5</code>"</dt>
                    488:    <dt>"<code>text/jscript</code>"</dt>
                    489:    <dt>"<code>text/livescript</code>"</dt>
                    490:    <dt>"<code>text/x-ecmascript</code>"</dt>
                    491:    <dt>"<code>text/x-javascript</code>"</dt>
                    492:    <dd>JavaScript. <a href="references.html#refsECMA262">[ECMA262]</a></dd>
                    493: 
                    494:    <dt>"<code>text/javascript;e4x=1</code>"</dt>
                    495:    <dd>JavaScript with ECMAScript for XML. <a href="references.html#refsECMA357">[ECMA357]</a></dd>
                    496: 
1.16      mike      497:   </dl><h5 id="restrictions-for-contents-of-script-elements"><span class="secno">4.3.1.2 </span><dfn title="script content restrictions">Restrictions for contents of <code>script</code> elements</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><p>The <code><a href="#textcontent">textContent</a></code> of a <code><a href="#script">script</a></code> element must match the
1.11      mike      498:   <code title="">script</code> production in the following ABNF, the
                    499:   character set for which is Unicode. <a href="references.html#refsABNF">[ABNF]</a></p><pre>script        = data1 *( escape [ script-start data3 ] "--&gt;" data1 ) [ escape ]
                    500: escape        = "&lt;!--" data2 *( script-start data3 script-end data2 )
                    501: 
                    502: data1         = &lt;any string that doesn't contain a substring that matches not-data1&gt;
                    503: not-data1     = <!-- script-end / -->"&lt;!--"             <!-- the script-end is redundant here since it would close the element -->
                    504: 
                    505: data2         = &lt;any string that doesn't contain a substring that matches not-data2&gt;
                    506: not-data2     = <!-- script-end / -->script-start / "--&gt;"  <!-- the script-end is redundant here since it would close the element -->
                    507: 
                    508: data3         = &lt;any string that doesn't contain a substring that matches not-data3&gt;
                    509: not-data3     = script-end / "--&gt;"
                    510: 
                    511: script-start  = lt       s c r i p t tag-end
                    512: script-end    = lt slash s c r i p t tag-end
                    513: 
                    514: lt            =  %x003C ; U+003C LESS-THAN SIGN character (&lt;)
                    515: slash         =  %x002F ; U+002F SOLIDUS character (/)
                    516: 
                    517: s             =  %x0053 ; U+0053 LATIN CAPITAL LETTER S
                    518: s             =/ %x0073 ; U+0073 LATIN SMALL LETTER S
                    519: c             =  %x0043 ; U+0043 LATIN CAPITAL LETTER C
                    520: c             =/ %x0063 ; U+0063 LATIN SMALL LETTER C
                    521: r             =  %x0052 ; U+0052 LATIN CAPITAL LETTER R
                    522: r             =/ %x0072 ; U+0072 LATIN SMALL LETTER R
                    523: i             =  %x0049 ; U+0049 LATIN CAPITAL LETTER I
                    524: i             =/ %x0069 ; U+0069 LATIN SMALL LETTER I
                    525: p             =  %x0050 ; U+0050 LATIN CAPITAL LETTER P
                    526: p             =/ %x0070 ; U+0070 LATIN SMALL LETTER P
                    527: t             =  %x0054 ; U+0054 LATIN CAPITAL LETTER T
                    528: t             =/ %x0074 ; U+0074 LATIN SMALL LETTER T
                    529: 
                    530: tag-end       =  %x0009 ; U+0009 CHARACTER TABULATION
                    531: tag-end       =/ %x000A ; U+000A LINE FEED (LF)
                    532: tag-end       =/ %x000C ; U+000C FORM FEED (FF)
                    533: tag-end       =/ %x0020 ; U+0020 SPACE
                    534: tag-end       =/ %x002F ; U+002F SOLIDUS (/)
                    535: tag-end       =/ %x003E ; U+003E GREATER-THAN SIGN (&gt;)</pre><p>When a <code><a href="#script">script</a></code> element contains <a href="#inline-documentation-for-external-scripts">script
                    536:   documentation</a>, there are further restrictions on the contents
                    537:   of the element, as described in the section below.</p><h5 id="inline-documentation-for-external-scripts"><span class="secno">4.3.1.3 </span><dfn title="script documentation">Inline documentation for external scripts</dfn></h5><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><p>If a <code><a href="#script">script</a></code> element's <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute is specified, then the
                    538:   contents of the <code><a href="#script">script</a></code> element, if any, must be such
                    539:   that the value of the <code title="dom-script-text"><a href="#dom-script-text">text</a></code> IDL
                    540:   attribute, which is derived from the element's contents, matches the
                    541:   <code title="">documentation</code> production in the following
                    542:   ABNF, the character set for which is Unicode. <a href="references.html#refsABNF">[ABNF]</a></p><pre>documentation = *( *( space / tab / comment ) [ line-comment ] newline )
                    543: comment       = slash star *( not-star / star not-slash ) 1*star slash
                    544: line-comment  = slash slash *not-newline
                    545: 
                    546: ; characters
                    547: tab           = %x0009 ; U+0009 TAB
                    548: newline       = %x000A ; U+000A LINE FEED (LF)
                    549: space         = %x0020 ; U+0020 SPACE
                    550: star          = %x002A ; U+002A ASTERISK (*)
                    551: slash         = %x002F ; U+002F SOLIDUS (/)
                    552: not-newline   = %x0000-0009 / %x000B-10FFFF
                    553:                 ; a Unicode character other than U+000A LINE FEED (LF)
                    554: not-star      = %x0000-0029 / %x002B-10FFFF
                    555:                 ; a Unicode character other than U+002A ASTERISK (*)
                    556: not-slash     = %x0000-002E / %x0030-10FFFF
                    557:                 ; a Unicode character other than U+002F SOLIDUS (/)</pre><p class="note">This corresponds to putting the contents of the
                    558:   element in JavaScript comments.</p><p class="note">This requirement is in addition to the earlier
                    559:   restrictions on the syntax of contents of <code><a href="#script">script</a></code>
                    560:   elements.</p><div class="example">
                    561: 
                    562:    <p>This allows authors to include documentation, such as license
                    563:    information or API information, inside their documents while still
                    564:    referring to external script files. The syntax is constrained so
                    565:    that authors don't accidentally include what looks like valid
                    566:    script while also providing a <code title="attr-script-src"><a href="#attr-script-src">src</a></code> attribute.</p>
                    567: 
                    568:    <pre>&lt;script src="cool-effects.js"&gt;
                    569:  // create new instances using:
                    570:  //    var e = new Effect();
                    571:  // start the effect using .play, stop using .stop:
                    572:  //    e.play();
                    573:  //    e.stop();
                    574: &lt;/script&gt;</pre>
                    575: 
                    576:   </div><h4 id="the-noscript-element"><span class="secno">4.3.2 </span>The <dfn><code>noscript</code></dfn> element</h4><p class="XXX annotation"><b>Status: </b><i>Last call for comments</i></p><dl class="element"><dt>Categories</dt>
                    577:    <dd><a href="content-models.html#metadata-content">Metadata content</a>.</dd>
                    578:    <dd><a href="content-models.html#flow-content">Flow content</a>.</dd>
                    579:    <dd><a href="content-models.html#phrasing-content">Phrasing content</a>.</dd>
                    580:    <dt>Contexts in which this element may be used:</dt>
                    581:    <dd>In a <code><a href="semantics.html#the-head-element-0">head</a></code> element of an <a href="dom.html#html-documents" title="HTML documents">HTML document</a>, if there are no ancestor <code><a href="#the-noscript-element">noscript</a></code> elements.</dd>
                    582:    <dd>Where <a href="content-models.html#phrasing-content">phrasing content</a> is expected in <a href="dom.html#html-documents">HTML documents</a>, if there are no ancestor <code><a href="#the-noscript-element">noscript</a></code> elements.</dd>
                    583:    <dt>Content model:</dt>
                    584:    <dd>When <a href="#concept-n-noscript" title="concept-n-noscript">scripting is disabled</a>, in a <code><a href="semantics.html#the-head-element-0">head</a></code> element: in any order, zero or more <code><a href="semantics.html#the-link-element">link</a></code> elements, zero or more <code><a href="semantics.html#the-style-element">style</a></code> elements, and zero or more <code><a href="semantics.html#meta">meta</a></code> elements.</dd>
                    585:    <dd>When <a href="#concept-n-noscript" title="concept-n-noscript">scripting is disabled</a>, not in a <code><a href="semantics.html#the-head-element-0">head</a></code> element: <a href="content-models.html#transparent">transparent</a>, but there must be no <code><a href="#the-noscript-element">noscript</a></code> element descendants.</dd>
                    586:    <dd>Otherwise: text that conforms to the requirements given in the prose.</dd>
                    587:    <dt>Content attributes:</dt>
                    588:    <dd><a href="elements.html#global-attributes">Global attributes</a></dd>
                    589:    <dt>DOM interface:</dt>
                    590:    <dd>Uses <code><a href="elements.html#htmlelement">HTMLElement</a></code>.</dd>
                    591:   </dl><p>The <code><a href="#the-noscript-element">noscript</a></code> element <a href="#represents">represents</a> nothing
                    592:   if <a href="#concept-n-script" title="concept-n-script">scripting is enabled</a>, and
                    593:   <a href="#represents">represents</a> its children if <a href="#concept-n-noscript" title="concept-n-noscript">scripting is disabled</a>. It is used
                    594:   to present different markup to user agents that support scripting
                    595:   and those that don't support scripting, by affecting how the
                    596:   document is parsed.</p><p>When used in <a href="dom.html#html-documents">HTML documents</a>, the allowed content
                    597:   model is as follows:</p><dl><dt>In a <code><a href="semantics.html#the-head-element-0">head</a></code> element, if <a href="#concept-n-noscript" title="concept-n-noscript">scripting is disabled</a> for the
                    598:    <code><a href="#the-noscript-element">noscript</a></code> element</dt>
                    599: 
                    600:    <dd><p>The <code><a href="#the-noscript-element">noscript</a></code> element must contain only
                    601:    <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="semantics.html#the-style-element">style</a></code>, and <code><a href="semantics.html#meta">meta</a></code>
                    602:    elements.</p></dd>
                    603: 
                    604:    <dt>In a <code><a href="semantics.html#the-head-element-0">head</a></code> element, if <a href="#concept-n-script" title="concept-n-script">scripting is enabled</a> for the
                    605:    <code><a href="#the-noscript-element">noscript</a></code> element</dt>
                    606: 
                    607:    <dd><p>The <code><a href="#the-noscript-element">noscript</a></code> element must contain only text,
                    608:    except that invoking the <a href="#html-fragment-parsing-algorithm">HTML fragment parsing
1.12      mike      609:    algorithm</a> <!-- (which disables <script type="text/javascript"> execution) --> with
1.11      mike      610:    the <code><a href="#the-noscript-element">noscript</a></code> element as the <var title="">context</var> element and the text contents as the <var title="">input</var> must result in a list of nodes that consists
                    611:    only of <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="semantics.html#the-style-element">style</a></code>, and
                    612:    <code><a href="semantics.html#meta">meta</a></code> elements that would be conforming if they were
                    613:    children of the <code><a href="#the-noscript-element">noscript</a></code> element, and no <a href="#parse-error" title="parse error">parse errors</a>.</p></dd>
                    614: 
                    615:    <dt>Outside of <code><a href="semantics.html#the-head-element-0">head</a></code> elements, if <a href="#concept-n-noscript" title="concept-n-noscript">scripting is disabled</a> for the
                    616:    <code><a href="#the-noscript-element">noscript</a></code> element</dt>
                    617: 
                    618:    <dd><p>The <code><a href="#the-noscript-element">noscript</a></code> element's content model is
                    619:    <a href="content-models.html#transparent">transparent</a>, with the additional restriction that a
                    620:    <code><a href="#the-noscript-element">noscript</a></code> element must not have a <code><a href="#the-noscript-element">noscript</a></code>
                    621:    element as an ancestor (that is, <code><a href="#the-noscript-element">noscript</a></code> can't be
                    622:    nested).</p></dd>
                    623: 
                    624:    <dt>Outside of <code><a href="semantics.html#the-head-element-0">head</a></code> elements, if <a href="#concept-n-script" title="concept-n-script">scripting is enabled</a> for the
                    625:    <code><a href="#the-noscript-element">noscript</a></code> element</dt>
                    626: 
                    627:    <dd>
                    628: 
                    629:     <p>The <code><a href="#the-noscript-element">noscript</a></code> element must contain only text,
                    630:     except that the text must be such that running the following
                    631:     algorithm results in a conforming document with no
                    632:     <code><a href="#the-noscript-element">noscript</a></code> elements and no <code><a href="#script">script</a></code>
                    633:     elements, and such that no step in the algorithm causes an
                    634:     <a href="#html-parser">HTML parser</a> to flag a <a href="#parse-error">parse error</a>:</p>
                    635: 
                    636:     <ol><li>Remove every <code><a href="#script">script</a></code> element from the
                    637:      document.</li>
                    638: 
                    639:      <li>Make a list of every <code><a href="#the-noscript-element">noscript</a></code> element in the
                    640:      document. For every <code><a href="#the-noscript-element">noscript</a></code> element in that list,
                    641:      perform the following steps:
                    642: 
                    643:       <ol><li>Let the <var title="">parent element</var> be the parent
                    644:        element of the <code><a href="#the-noscript-element">noscript</a></code> element.</li>
                    645: 
                    646:        <li>Take all the children of the <var title="">parent element</var>
                    647:        that come before the <code><a href="#the-noscript-element">noscript</a></code> element, and call these
                    648:        elements <var title="">the before children</var>.</li>
                    649: 
                    650:        <li>Take all the children of the <var title="">parent element</var>
                    651:        that come <em>after</em> the <code><a href="#the-noscript-element">noscript</a></code> element, and
                    652:        call these elements <var title="">the after children</var>.</li>
                    653: 
                    654:        <li>Let <var title="">s</var> be the concatenation of all the
                    655:        <a href="infrastructure.html#text-node">text node</a> children of the <code><a href="#the-noscript-element">noscript</a></code>
                    656:        element.</li>
                    657: 
                    658:        <li>Set the <code title="dom-innerHTML"><a href="apis-in-html-documents.html#dom-innerhtml">innerHTML</a></code>
                    659:        attribute of the <var title="">parent element</var> to the value
                    660:        of <var title="">s</var>. (This, as a side-effect, causes the
                    661:        <code><a href="#the-noscript-element">noscript</a></code> element to be removed from the
                    662:        document.)</li>
                    663: 
                    664:        <li>Insert <var title="">the before children</var> at the start of
                    665:        the <var title="">parent element</var>, preserving their original
                    666:        relative order.</li>
                    667: 
                    668:        <li>Insert <var title="">the after children</var> at the end of the
                    669:        <var title="">parent element</var>, preserving their original
                    670:        relative order.</li>
                    671: 
                    672:       </ol></li>
                    673: 
                    674:     </ol></dd>
                    675: 
                    676:   </dl><p class="note">All these contortions are required because, for
                    677:   historical reasons, the <code><a href="#the-noscript-element">noscript</a></code> element is handled
                    678:   differently by the <a href="#html-parser">HTML parser</a> based on whether <a href="#scripting-flag" title="scripting flag">scripting was enabled or not</a> when the
                    679:   parser was invoked.</p><p>The <code><a href="#the-noscript-element">noscript</a></code> element must not be used in <a href="dom.html#xml-documents">XML
                    680:   documents</a>.</p><p class="note"><strong>The <code><a href="#the-noscript-element">noscript</a></code> element is only
                    681:   effective in <a href="syntax.html#syntax">the HTML syntax</a>, it has no effect in
                    682:   <a href="the-xhtml-syntax.html#the-xhtml-syntax">the XHTML syntax</a>.</strong></p><div class="example">
                    683: 
                    684:    <p>In the following example, a <code><a href="#the-noscript-element">noscript</a></code> element is
                    685:    used to provide fallback for a script.</p>
                    686: 
                    687:    <pre>&lt;form action="calcSquare.php"&gt;
                    688:  &lt;p&gt;
                    689:   &lt;label for=x&gt;Number&lt;/label&gt;:
                    690:   &lt;input id="x" name="x" type="number"&gt;
                    691:  &lt;/p&gt;
                    692:  &lt;script&gt;
                    693:   var x = document.getElementById('x');
                    694:   var output = document.createElement('p');
                    695:   output.textContent = 'Type a number; it will be squared right then!';
                    696:   x.form.appendChild(output);
                    697:   x.form.onsubmit = function () { return false; }
                    698:   x.oninput = function () {
                    699:     var v = x.valueAsNumber;
                    700:     output.textContent = v + ' squared is ' + v * v;
                    701:   };
                    702:  &lt;/script&gt;
                    703:  &lt;noscript&gt;
                    704:   &lt;input type=submit value="Calculate Square"&gt;
                    705:  &lt;/noscript&gt;
                    706: &lt;/form&gt;</pre>
                    707: 
                    708:    <p>When script is disabled, a button appears to do the calculation
                    709:    on the server side. When script is enabled, the value is computed
                    710:    on-the-fly instead.</p>
                    711: 
                    712:    <p>The <code><a href="#the-noscript-element">noscript</a></code> element is a blunt
                    713:    instrument. Sometimes, scripts might be enabled, but for some
                    714:    reason the page's script might fail. For this reason, it's
                    715:    generally better to avoid using <code><a href="#the-noscript-element">noscript</a></code>, and to
                    716:    instead design the script to change the page from being a
                    717:    scriptless page to a scripted page on the fly, as in the next
                    718:    example:</p>
                    719: 
                    720:    <pre>&lt;form action="calcSquare.php"&gt;
                    721:  &lt;p&gt;
                    722:   &lt;label for=x&gt;Number&lt;/label&gt;:
                    723:   &lt;input id="x" name="x" type="number"&gt;
                    724:  &lt;/p&gt;
                    725:  <strong>&lt;input id="submit" type=submit value="Calculate Square"&gt;</strong>
                    726:  &lt;script&gt;
                    727:   var x = document.getElementById('x');
                    728:   var output = document.createElement('p');
                    729:   output.textContent = 'Type a number; it will be squared right then!';
                    730:   x.form.appendChild(output);
                    731:   x.form.onsubmit = function () { return false; }
                    732:   x.oninput = function () {
                    733:     var v = x.valueAsNumber;
                    734:     output.textContent = v + ' squared is ' + v * v;
                    735:   };
                    736: <strong>  var submit = document.getElementById('submit');
                    737:   submit.parentNode.removeChild(submit);</strong>
                    738:  &lt;/script&gt;
                    739: &lt;/form&gt;</pre>
                    740: 
                    741:    <p>The above technique is also useful in XHTML, since
                    742:    <code><a href="#the-noscript-element">noscript</a></code> is not supported in <a href="the-xhtml-syntax.html#the-xhtml-syntax">the XHTML
                    743:    syntax</a>.</p>
                    744: 
                    745:   </div></body></html>

Webmaster