Annotation of html5/spec/scripting-1.html, revision 1.164
1.163 mike 1: <!doctype html>
1.164 ! mike 2: <!DOCTYPE html>
1.77 mike 3: <html lang="en-US-x-Hixie"><head><title>4.3 Scripting — HTML5</title><style type="text/css">
1.1 mike 4: pre { margin-left: 2em; white-space: pre-wrap; }
5: h2 { margin: 3em 0 1em 0; }
6: h3 { margin: 2.5em 0 1em 0; }
7: h4 { margin: 2.5em 0 0.75em 0; }
8: h5, h6 { margin: 2.5em 0 1em; }
9: h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
10: h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
11: p { margin: 1em 0; }
12: hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
13: dl, dd { margin-top: 0; margin-bottom: 0; }
14: dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
15: dt + dt { margin-top: 0; }
16: dd dt { margin-top: 0.25em; margin-bottom: 0; }
17: dd p { margin-top: 0; }
18: dd dl + p { margin-top: 1em; }
19: dd table + p { margin-top: 1em; }
20: p + * > li, dd li { margin: 1em 0; }
21: dt, dfn { font-weight: bold; font-style: normal; }
1.64 mike 22: i, em { font-style: italic; }
1.1 mike 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; }
30: table thead, table tbody { border-bottom: solid; }
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; }
1.68 mike 44: img.extra, p.overview { float: right; }
1.67 mike 45: pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; position: relative; }
1.1 mike 46: pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
1.67 mike 47: pre.idl::before { content: "IDL"; font: bold small sans-serif; padding: 0.5em; background: white; position: absolute; top: 0; margin: -1px 0 0 -4em; width: 1.5em; border: thin solid; border-radius: 0 0 0 0.5em }
1.1 mike 48: pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
49: pre.css:first-line { color: #AAAA50; }
50: dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #DDFFDD; }
51: hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
52: dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
53: dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
54: dl.domintro dd p { margin: 0.5em 0; }
1.74 mike 55: dl.domintro:before { display: table; margin: -1em -0.5em -0.5em auto; width: auto; content: 'This box is non-normative. Implementation requirements are given below this box.'; color: black; font-style: italic; border: solid 2px; background: white; padding: 0 0.25em; }
1.1 mike 56: dl.switch { padding-left: 2em; }
57: dl.switch > dt { text-indent: -1.5em; }
58: dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
59: dl.triple { padding: 0 0 0 1em; }
60: dl.triple dt, dl.triple dd { margin: 0; display: inline }
61: dl.triple dt:after { content: ':'; }
62: dl.triple dd:after { content: '\A'; white-space: pre; }
63: .diff-old { text-decoration: line-through; color: silver; background: transparent; }
64: .diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
65: a .diff-new { border-bottom: 1px blue solid; }
66:
67: h2 { page-break-before: always; }
68: h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
69: h1 + h2, hr + h2.no-toc { page-break-before: auto; }
70:
1.29 mike 71: p > span:not([title=""]):not([class="XXX"]):not([class="impl"]):not([class="note"]),
72: li > span:not([title=""]):not([class="XXX"]):not([class="impl"]):not([class="note"]), { border-bottom: solid #9999CC; }
1.1 mike 73:
74: div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
75: div.head p { margin: 0; }
76: div.head h1 { margin: 0; }
77: div.head .logo { float: right; margin: 0 1em; }
78: div.head .logo img { border: none } /* remove border from top image */
79: div.head dl { margin: 1em 0; }
80: div.head p.copyright, div.head p.alt { font-size: x-small; font-style: oblique; margin: 0; }
81:
82: body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
83: body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
84: body > .toc > li > * { margin-bottom: 0.5em; }
85: body > .toc > li > * > li > * { margin-bottom: 0.25em; }
86: .toc, .toc li { list-style: none; }
87:
88: .brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
89: .brief li { margin: 0; padding: 0; }
90: .brief li p { margin: 0; padding: 0; }
91:
92: .category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
93: .category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
94: .category-list li { display: inline; }
95: .category-list li:not(:last-child)::after { content: ', '; }
96: .category-list li > span, .category-list li > a { text-transform: lowercase; }
97: .category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
98:
99: .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
100: .XXX > :first-child { margin-top: 0; }
101: p .XXX { line-height: 3em; }
102: .annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
103: .annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
104: .annotation :link, .annotation :visited { color: inherit; }
105: .annotation :link:hover, .annotation :visited:hover { background: transparent; }
106: .annotation span { border: none ! important; }
107: .note { color: green; background: transparent; font-family: sans-serif; }
108: .warning { color: red; background: transparent; }
109: .note, .warning { font-weight: bolder; font-style: italic; }
1.64 mike 110: .note em, .warning em, .note i, .warning i { font-style: normal; }
1.1 mike 111: p.note, div.note { padding: 0.5em 2em; }
112: span.note { padding: 0 2em; }
113: .note p:first-child, .warning p:first-child { margin-top: 0; }
114: .note p:last-child, .warning p:last-child { margin-bottom: 0; }
115: .warning:before { font-style: normal; }
116: p.note:before { content: 'Note: '; }
117: p.warning:before { content: '\26A0 Warning! '; }
118:
119: .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
120: .bookkeeping { font-size: 0.8em; margin: 2em 0; }
121: .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
1.9 mike 122: .bookkeeping dt { margin: 0.5em 2em 0; }
123: .bookkeeping dd { margin: 0 3em 0.5em; }
1.1 mike 124:
125: h4 { position: relative; z-index: 3; }
126: h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
127: .element {
128: background: #EEEEFF;
129: color: black;
130: margin: 0 0 1em 0.15em;
131: padding: 0 1em 0.25em 0.75em;
132: border-left: solid #9999FF 0.25em;
133: position: relative;
134: z-index: 1;
135: }
136: .element:before {
137: position: absolute;
138: z-index: 2;
139: top: 0;
140: left: -1.15em;
141: height: 2em;
142: width: 0.9em;
143: background: #EEEEFF;
144: content: ' ';
145: border-style: none none solid solid;
146: border-color: #9999FF;
147: border-width: 0.25em;
148: }
149:
150: .example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
151: td > .example:only-child { margin: 0 0 0 0.1em; }
152:
153: ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
154: ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
155: ul.domTree li li { list-style: none; }
156: 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; }
157: 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; }
158: ul.domTree span { font-style: italic; font-family: serif; }
159: ul.domTree .t1 code { color: purple; font-weight: bold; }
160: ul.domTree .t2 { font-style: normal; font-family: monospace; }
161: ul.domTree .t2 .name { color: black; font-weight: bold; }
162: ul.domTree .t2 .value { color: blue; font-weight: normal; }
163: ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
164: ul.domTree .t7 code, .domTree .t8 code { color: green; }
165: ul.domTree .t10 code { color: teal; }
166:
167: body.dfnEnabled dfn { cursor: pointer; }
168: .dfnPanel {
169: display: inline;
170: position: absolute;
171: z-index: 10;
172: height: auto;
173: width: auto;
174: padding: 0.5em 0.75em;
175: font: small sans-serif, Droid Sans Fallback;
176: background: #DDDDDD;
177: color: black;
178: border: outset 0.2em;
179: }
180: .dfnPanel * { margin: 0; padding: 0; font: inherit; text-indent: 0; }
181: .dfnPanel :link, .dfnPanel :visited { color: black; }
182: .dfnPanel p { font-weight: bolder; }
183: .dfnPanel * + p { margin-top: 0.25em; }
184: .dfnPanel li { list-style-position: inside; }
185:
186: #configUI { position: absolute; z-index: 20; top: 10em; right: 1em; width: 11em; font-size: small; }
187: #configUI p { margin: 0.5em 0; padding: 0.3em; background: #EEEEEE; color: black; border: inset thin; }
188: #configUI p label { display: block; }
189: #configUI #updateUI, #configUI .loginUI { text-align: center; }
190: #configUI input[type=button] { display: block; margin: auto; }
1.8 mike 191:
1.33 mike 192: fieldset { margin: 1em; padding: 0.5em 1em; }
193: fieldset > legend + * { margin-top: 0; }
1.28 mike 194: fieldset > :last-child { margin-bottom: 0; }
1.33 mike 195: fieldset p { margin: 0.5em 0; }
196:
1.161 mike 197: .stability {
198: position: fixed;
199: bottom: 0;
200: left: 0; right: 0;
201: margin: 0 auto 0 auto;
202: width: 50%;
203: background: maroon; color: yellow;
204: -webkit-border-radius: 1em 1em 0 0;
205: -moz-border-radius: 1em 1em 0 0;
206: border-radius: 1em 1em 0 0;
207: -moz-box-shadow: 0 0 1em #500;
208: -webkit-box-shadow: 0 0 1em #500;
209: box-shadow: 0 0 1em red;
210: padding: 0.5em 1em;
211: text-align: center;
212: }
213: .stability strong {
214: display: block;
215: }
216: .stability input {
217: appearance: none; margin: 0; border: 0; padding: 0.25em 0.5em; background: transparent; color: black;
218: position: absolute; top: -0.5em; right: 0; font: 1.25em sans-serif; text-align: center;
219: }
220: .stability input:hover {
221: color: white;
222: text-shadow: 0 0 2px black;
223: }
224: .stability input:active {
225: padding: 0.3em 0.45em 0.2em 0.55em;
226: }
227: .stability :link, .stability :visited,
228: .stability :link:hover, .stability :visited:hover {
229: background: transparent;
230: color: white;
231: }
232:
233: </style><link href="http://www.w3.org/StyleSheets/TR/W3C-WD" rel="stylesheet" type="text/css"><meta content="noindex" name="robots"><style type="text/css">
1.1 mike 234:
235: .applies thead th > * { display: block; }
236: .applies thead code { display: block; }
237: .applies tbody th { whitespace: nowrap; }
238: .applies td { text-align: center; }
239: .applies .yes { background: yellow; }
240:
1.10 mike 241: .matrix, .matrix td { border: hidden; text-align: right; }
1.1 mike 242: .matrix { margin-left: 2em; }
243:
244: .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
245: .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
246: .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
247:
1.17 mike 248: td.eg { border-width: thin; text-align: center; }
249:
1.1 mike 250: #table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
251: #table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
252: #table-example-1 caption { padding-bottom: 0.5em; }
253: #table-example-1 thead, #table-example-1 tbody { border: none; }
254: #table-example-1 th, #table-example-1 td { border: solid thin; }
255: #table-example-1 th { font-weight: normal; }
256: #table-example-1 td { border-style: none solid; vertical-align: top; }
257: #table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
258: #table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
259: #table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
260: #table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
261: #table-example-1 tbody td:first-child::after { content: leader(". "); }
262: #table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
263: #table-example-1 tbody td:first-child + td { width: 10em; }
264: #table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
265: #table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
266:
267: .apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
268: .apple-table-examples * { font-family: "Times", serif; }
269: .apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
270: .apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
271: .apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
272: .apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
273: .apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
274: .apple-table-examples td { text-align: right; vertical-align: top; }
275: .apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
276: .apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
277: .apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
278: .apple-table-examples sup { line-height: 0; }
279:
280: .details-example img { vertical-align: top; }
281:
1.39 mike 282: #base64-table {
283: white-space: nowrap;
284: font-size: 0.6em;
285: column-width: 6em;
286: column-count: 5;
287: column-gap: 1em;
288: -moz-column-width: 6em;
289: -moz-column-count: 5;
290: -moz-column-gap: 1em;
291: -webkit-column-width: 6em;
292: -webkit-column-count: 5;
293: -webkit-column-gap: 1em;
294: }
295: #base64-table thead { display: none; }
296: #base64-table * { border: none; }
297: #base64-table tbody td:first-child:after { content: ':'; }
298: #base64-table tbody td:last-child { text-align: right; }
299:
1.1 mike 300: #named-character-references-table {
1.24 mike 301: white-space: nowrap;
1.1 mike 302: font-size: 0.6em;
1.24 mike 303: column-width: 30em;
1.1 mike 304: column-gap: 1em;
1.24 mike 305: -moz-column-width: 30em;
1.1 mike 306: -moz-column-gap: 1em;
1.24 mike 307: -webkit-column-width: 30em;
1.1 mike 308: -webkit-column-gap: 1em;
309: }
1.24 mike 310: #named-character-references-table > table > tbody > tr > td:first-child + td,
1.1 mike 311: #named-character-references-table > table > tbody > tr > td:last-child { text-align: center; }
312: #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.24 mike 313: #named-character-references-table > table > tbody > tr#entity-CounterClockwiseContourIntegral > td:first-child { font-size: 0.5em; }
1.1 mike 314:
1.2 mike 315: .glyph.control { color: red; }
316:
1.4 mike 317: @font-face {
318: font-family: 'Essays1743';
319: src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743.ttf');
320: }
321: @font-face {
322: font-family: 'Essays1743';
323: font-weight: bold;
324: src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-Bold.ttf');
325: }
326: @font-face {
327: font-family: 'Essays1743';
328: font-style: italic;
329: src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-Italic.ttf');
330: }
331: @font-face {
332: font-family: 'Essays1743';
333: font-style: italic;
334: font-weight: bold;
335: src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-BoldItalic.ttf');
336: }
337:
1.57 mike 338: </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.47 mike 339: function getCookie(name) {
340: var params = location.search.substr(1).split("&");
341: for (var index = 0; index < params.length; index++) {
342: if (params[index] == name)
343: return "1";
344: var data = params[index].split("=");
345: if (data[0] == name)
346: return unescape(data[1]);
347: }
348: var cookies = document.cookie.split("; ");
349: for (var index = 0; index < cookies.length; index++) {
350: var data = cookies[index].split("=");
351: if (data[0] == name)
352: return unescape(data[1]);
353: }
354: return null;
355: }
356: </script>
1.1 mike 357: <script src="link-fixup.js"></script>
1.77 mike 358: <link href="styling.html" title="4.2.7 Styling" rel="prev">
359: <link href="index.html#contents" title="Table of contents" rel="contents">
360: <link href="the-script-element.html" title="4.3.1 The script element" rel="next">
1.98 mike 361: </head><body onload="fixBrokenLink();" class="split chapter"><div class="head" id="head">
1.1 mike 362: <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.3 mike 363:
1.1 mike 364: <h1>HTML5</h1>
1.162 mike 365: <h2 class="no-num no-toc" id="a-vocabulary-and-associated-apis-for-html-and-xhtml">A vocabulary and associated APIs for HTML and XHTML</h2><p>This is revision 1.5609.</p>
1.161 mike 366:
367: <h2 class="no-num no-toc" id="w3c-working-draft-15-april-2012">W3C Working Draft 15 April 2012</h2>
368: </div>
1.77 mike 369:
1.161 mike 370: <nav class="prev_next">
1.77 mike 371: <a href="styling.html">← 4.2.7 Styling</a> –
372: <a href="index.html#contents">Table of contents</a> –
373: <a href="the-script-element.html">4.3.1 The script element →</a>
374: </nav>
1.1 mike 375:
1.161 mike 376: <h3 id="scripting-1"><span class="secno">4.3 </span>Scripting</h3>
377:
378: <p>Scripts allow authors to add interactivity to their documents.</p>
379:
380: <p>Authors are encouraged to use declarative alternatives to
1.1 mike 381: scripting where possible, as declarative mechanisms are often more
1.161 mike 382: maintainable, and many users disable scripting.</p>
383:
384: <div class="example">
1.1 mike 385: <p>For example, instead of using script to show or hide a section
1.77 mike 386: to show more details, the <code><a href="the-details-element.html#the-details-element">details</a></code> element could be
1.1 mike 387: used.</p>
1.161 mike 388: </div>
389:
390: <p>Authors are also encouraged to make their applications degrade
391: gracefully in the absence of scripting support.</p>
392:
393: <div class="example">
1.1 mike 394: <p>For example, if an author provides a link in a table header to
395: dynamically resort the table, the link could also be made to
396: function without scripts by requesting the sorted table from the
397: server.</p>
1.161 mike 398: </div>
399:
400:
401: </body></html>
Webmaster