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