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

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

Webmaster