forked from w3c/dom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverview.src.html
9157 lines (7416 loc) · 404 KB
/
Overview.src.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html><html lang=en-US><meta charset=utf-8>
<title>DOM Standard</title>
<link rel=stylesheet href=http://www.whatwg.org/style/specification>
<link rel=icon href=//resources.whatwg.org/logo-dom.svg>
<div class=head>
<p><a class=logo href=//www.whatwg.org/><img alt=WHATWG src=//resources.whatwg.org/logo-dom.svg width=100 height=100></a></p>
<h1 class=allcaps>DOM</h1>
<h2 class="no-num no-toc">Living Standard — Last Updated [DATE: 01 Jan 1901]</h2>
<dl>
<dt>This Version:
<dd><a href="http://dom.spec.whatwg.org/">http://dom.spec.whatwg.org/</a>
<dt>Participate:</dt>
<dd class=dontpublish>Send feedback to
<a href="mailto:[email protected]?subject=DOM%3A%20">[email protected]</a> (<a href="http://lists.w3.org/Archives/Public/www-dom/">archives</a>) or
<a href="https://www.w3.org/Bugs/Public/enter_bug.cgi?product=WebAppsWG&component=DOM">file a bug</a>
(<a href="https://www.w3.org/Bugs/Public/buglist.cgi?product=WebAppsWG&component=DOM&resolution=---">open bugs</a>)
<dd class=dontpublish><a href="http://wiki.whatwg.org/wiki/IRC">IRC: #whatwg on Freenode</a>
<dt>Version History:
<dd><a href=https://github.com/whatwg/dom/commits>https://github.com/whatwg/dom/commits</a>
<dd><a href="https://twitter.com/thedomstandard">@thedomstandard</a>
<dt>Editors:
<dd><a href="http://annevankesteren.nl/">Anne van Kesteren</a>
(<a href="http://www.mozilla.org/">Mozilla</a>)
<<a href="mailto:[email protected]">[email protected]</a>>
<dd>Aryeh Gregor
(<a href="http://www.mozilla.org/">Mozilla</a>)
<<a href=mailto:[email protected]>[email protected]</a>>
<dd>Ms2ger
(<a href="http://www.mozilla.org/">Mozilla</a>)
<<a href="mailto:[email protected]">[email protected]</a>>
</dl>
<script src=//resources.whatwg.org/file-bug.js async></script>
<p class=copyright><a rel="license" href="http://creativecommons.org/publicdomain/zero/1.0/"><img src="http://i.creativecommons.org/p/zero/1.0/80x15.png" alt="CC0"></a>
To the extent possible under law, the editors have waived all copyright and
related or neighboring rights to this work. In addition, as of
[DATE: 01 Jan 1901], the editors have made this specification available
under the
<a rel="license"
href="http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0">Open Web Foundation Agreement Version 1.0</a>,
which is available at
http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0.
</div>
<h2 class="no-num no-toc">Abstract</h2>
<p>DOM defines a platform-neutral model for events and node trees.
<h2 class="no-num no-toc">Table of Contents</h2>
<!--toc-->
<h2 class=no-num>Goals</h2>
<p>This specification standardizes the DOM. It does so as follows:</p>
<ol>
<li>
<p>By consolidating <cite>DOM Level 3 Core</cite>
<span data-anolis-ref class=informative>DOM3CORE</span>,
<cite>Element Traversal</cite>
<span data-anolis-ref class=informative>ELEMENTTRAVERSAL</span>,
<cite>Selectors API Level 2</cite>
<span data-anolis-ref class=informative>SELECTORSAPI</span>, the
"DOM Event Architecture" and "Basic Event Interfaces" chapters of
<cite>DOM Level 3 Events</cite>
<span data-anolis-ref class=informative>DOM3EVENTS</span> (specific type
of events do not belong in the base specification), and
<cite>DOM Level 2 Traversal and Range</cite>
<span data-anolis-ref class=informative>DOM2TR</span>, and:
<ul>
<li>Aligning them with the needs of JavaScript where possible.
<li>Aligning them with existing implementations.
<li>Simplifying them as much as possible.
</ul>
<li><p>By moving features from the HTML standard that ought to be part of the DOM
platform here. <span data-anolis-ref>HTML</span>
<li>
<p>By defining a replacement for the "Mutation Events" and
"Mutation Name Event Types" chapters of <cite>DOM Level 3 Events</cite>
<span data-anolis-ref class=informative>DOM3EVENTS</span> as the old model
was problematic.
<p class=note>The old model is expected to be removed from implementations
in due course.
<li><p>By defining new features that simplify common DOM operations.
</ol>
<h2>Conformance</h2>
<p>All diagrams, examples, and notes in this specification are
non-normative, as are all sections explicitly marked non-normative.
Everything else in this specification is normative.
<p>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
"OPTIONAL" in this document are to be interpreted as described in RFC 2119.
For readability, these words do not appear in all uppercase letters in this
specification. <span data-anolis-ref>RFC2119</span>
<p>Requirements phrased in the imperative as part of algorithms
(such as "strip any leading space characters" or "return false and
terminate these steps") are to be interpreted with the meaning of the
key word ("must", "should", "may", etc) used in introducing the
algorithm.
<p>Conformance requirements phrased as algorithms or specific steps
may be implemented in any manner, so long as the end result is
equivalent. (In particular, the algorithms defined in this
specification are intended to be easy to follow, and not intended to
be performant.)
<p id="hardwareLimitations">User agents may impose
implementation-specific limits on otherwise unconstrained inputs,
e.g. to prevent denial of service attacks, to guard against running
out of memory, or to work around platform-specific limitations.
<p>When a method or an attribute is said to call another method or attribute, the user agent must invoke its internal API for that attribute or method so that e.g. the author can't change the behavior by overriding attributes or methods with custom properties or functions in JavaScript.
<p>Unless otherwise stated, string comparisons are done in a <span>case-sensitive</span> manner.
<h3>Dependencies</h3>
<p>The IDL fragments in this specification must be interpreted as
required for conforming IDL fragments, as described in the Web IDL
specification. <span data-anolis-ref>WEBIDL</span>
<p>Some of the terms used in this specification are defined in
<cite>Encoding</cite>, <cite>Selectors</cite>, <cite>Web IDL</cite>, <cite>XML</cite>, and
<cite>Namespaces in XML</cite>.
<span data-anolis-ref>ENCODING</span>
<span data-anolis-ref>SELECTORS</span>
<span data-anolis-ref>WEBIDL</span>
<span data-anolis-ref>XML</span>
<span data-anolis-ref>XMLNS</span>
<h3>Extensibility</h3>
<p>Vendor-specific proprietary extensions to this specification are
strongly discouraged. Authors must not use such extensions, as
doing so reduces interoperability and fragments the user base,
allowing only users of specific user agents to access the content in
question.
<p>If vendor-specific extensions are needed, the members should be
prefixed by vendor-specific strings to prevent clashes with future
versions of this specification. Extensions must be defined so that
the use of extensions neither contradicts nor causes the
non-conformance of functionality defined in the specification.
<!-- thanks to QA Framework -->
<p>When vendor-neutral extensions to this specification are needed,
either this specification can be updated accordingly, or an
extension specification can be written that overrides the
requirements in this specification. When someone applying this
specification to their activities decides that they will recognize
the requirements of such an extension specification, it becomes an
<dfn title="other applicable specifications">applicable
specification</dfn> for the purposes of conformance requirements in
this specification.
<!-- http://www.w3.org/mid/[email protected] -->
<h2>Terminology</h2>
<p>The term <dfn>context object</dfn> means the object on which the algorithm,
attribute getter, attribute setter, or method being discussed was called. When the
<span>context object</span> is unambiguous, the term can be omitted.
<!-- XXX we should prolly explain that "set attribute X to Y" works even for
readonly attributes when it is language for implementors -->
<h3>Trees</h3> <!-- Sorry reddit, this is not /r/trees -->
<p>A <dfn title=concept-tree>tree</dfn> is a finite hierarchical tree structure. In
<dfn title=concept-tree-order>tree order</dfn> is preorder, depth-first
traversal of a <span title=concept-tree>tree</span>.
<!-- http://en.wikipedia.org/wiki/Tree_traversal#Depth-first_Traversal -->
<p>An object that <dfn title=concept-tree-participate>participates</dfn> in
a <span title=concept-tree>tree</span> has a
<dfn title=concept-tree-parent>parent</dfn>, which is either another object
or null, and an ordered list of zero or more
<dfn title=concept-tree-child>child</dfn> objects. An object <var title>A</var> whose
<span title=concept-tree-parent>parent</span> is object <var title>B</var> is a
<span title=concept-tree-child>child</span> of <var title>B</var>.
<p>The <dfn title=concept-tree-root>root</dfn> of an object is itself, if its
<span title=concept-tree-parent>parent</span> is null, or else it is the
<span title=concept-tree-root>root</span> of its
<span title=concept-tree-parent>parent</span>.
<p>An object <var title>A</var> is called a
<dfn title=concept-tree-descendant>descendant</dfn> of an object
<var title>B</var>, if either <var title>A</var> is a
<span title=concept-tree-child>child</span> of <var title>B</var> or
<var title>A</var> is a <span title=concept-tree-child>child</span> of an
object <var title>C</var> that is a
<span title=concept-tree-descendant>descendant</span> of <var title>B</var>.
<p>An
<dfn title=concept-tree-inclusive-descendant>inclusive descendant</dfn> is
an object or one of its
<span title=concept-tree-descendant>descendants</span>.
<p>An object <var title>A</var> is called an
<dfn title=concept-tree-ancestor>ancestor</dfn> of an object
<var title>B</var> if and only if <var title>B</var> is a
<span title=concept-tree-descendant>descendant</span> of
<var title>A</var>.
<p>An <dfn title=concept-tree-inclusive-ancestor>inclusive ancestor</dfn> is
an object or one of its <span title=concept-tree-ancestor>ancestors</span>.
<p>An object <var title>A</var> is called a
<dfn title=concept-tree-sibling>sibling</dfn> of an object
<var title>B</var>, if and only if <var title>B</var> and <var title>A</var>
share the same non-null <span title=concept-tree-parent>parent</span>.
<p>An object <var title>A</var> is
<dfn title=concept-tree-preceding>preceding</dfn> an object
<var title>B</var> if <var title>A</var> and <var title>B</var> are in the
same <span title=concept-tree>tree</span> and <var title>A</var> comes
before <var title>B</var> in
<span title=concept-tree-order>tree order</span>.
<p>An object <var title>A</var> is
<dfn title=concept-tree-following>following</dfn> an object
<var title>B</var> if <var title>A</var> and <var title>B</var> are in the
same <span title=concept-tree>tree</span> and <var title>A</var> comes
after <var title>B</var> in
<span title=concept-tree-order>tree order</span>.
<p>The <dfn title=concept-tree-first-child>first child</dfn> of an object is
its first <span title=concept-tree-child>child</span> or null if it has no
<span title=concept-tree-child>child</span>.
<p>The <dfn title=concept-tree-last-child>last child</dfn> of an object is
its last <span title=concept-tree-child>child</span> or null if it has no
<span title=concept-tree-child>child</span>.
<p>The <dfn title=concept-tree-previous-sibling>previous sibling</dfn> of an
object is its first <span title=concept-tree-preceding>preceding</span>
<span title=concept-tree-sibling>sibling</span> or null if it has no
<span title=concept-tree-preceding>preceding</span>
<span title=concept-tree-sibling>sibling</span>.
<p>The <dfn title=concept-tree-next-sibling>next sibling</dfn> of an
object is its first <span title=concept-tree-following>following</span>
<span title=concept-tree-sibling>sibling</span> or null if it has no
<span title=concept-tree-following>following</span>
<span title=concept-tree-sibling>sibling</span>.
<p>The <dfn title=concept-tree-index>index</dfn> of an object is its number
of <span title=concept-tree-preceding>preceding</span>
<span title=concept-tree-sibling>siblings</span>.
<h3>Strings</h3>
<p>Comparing two strings in a <dfn>case-sensitive</dfn> manner means comparing them exactly, code point for code point.
<p>Comparing two strings in a <dfn>ASCII case-insensitive</dfn> manner means comparing them exactly, code point for code point, except that the characters in the range U+0041 .. U+005A (i.e. LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z) and the corresponding characters in the range U+0061 .. U+007A (i.e. LATIN SMALL LETTER A to LATIN SMALL LETTER Z) are considered to also match.
<p><dfn title="converted to ascii uppercase">Converting a string to ASCII uppercase</dfn> means replacing all characters in the range U+0061 to U+007A (i.e. LATIN SMALL LETTER A to LATIN SMALL LETTER Z) with the corresponding characters in the range U+0041 to U+005A (i.e. LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z).
<p><dfn title="converted to ascii lowercase">Converting a string to ASCII lowercase</dfn> means replacing all characters in the range U+0041 to U+005A (i.e. LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z) with the corresponding characters in the range U+0061 to U+007A (i.e. LATIN SMALL LETTER A to LATIN SMALL LETTER Z).
<p>A string <var title>pattern</var> is a <dfn>prefix match</dfn> for a string
<var title>s</var> when <var title>pattern</var> is not longer than
<var title>s</var> and truncating <var title>s</var> to
<var title>pattern</var>'s length leaves the two strings as matches of each
other.
<h3>Ordered sets</h3>
<p>The <dfn title=concept-ordered-set-parser>ordered set parser</dfn> takes a string
<var title>input</var> and then runs these steps:
<ol>
<li><p>Let <var title>position</var> be a pointer into <var title>input</var>,
initially pointing at the start of the string.
<li><p>Let <var title>tokens</var> be an ordered set of tokens, initially empty.
<li><p><span>Skip ASCII whitespace</span>.
<li><p>While <var title>position</var> is not past the end of
<var title>input</var>:
<ol>
<li><p><span>Collect a code point sequence</span> of code points that are
not <span data-anolis-spec=encoding>ASCII whitespace</span>.
<li><p>If the collected string is not in <var title>tokens</var>, append the
collected string to <var title>tokens</var>.
<li><p><span>Skip ASCII whitespace</span>.
</ol>
<li><p>Return <var title>tokens</var>.
</ol>
<p>To <dfn>collect a code point sequence</dfn> of
<var title>code points</var>, run these steps:
<ol>
<li><p>Let <var title>input</var> and <var title>position</var> be the same
variables as those of the same name in the algorithm that invoked these
steps.
<li><p>Let <var title>result</var> be the empty string.
<li><p>While <var title>position</var> does not point past the end of
<var title>input</var> and the code point at <var title>position</var> is
one of <var title>code points</var>, append that code point to the end
of <var title>result</var> and advance <var title>position</var> to the
next code point in <var title>input</var>.
<li><p>Return <var title>result</var>.
</ol>
<p>To <dfn>skip ASCII whitespace</dfn> means to
<span>collect a code point sequence</span> of
<span data-anolis-spec=encoding>ASCII whitespace</span> and discard the
return value.
<p>The <dfn title=concept-ordered-set-serializer>ordered set serializer</dfn> takes a
<var title>set</var> and returns the concatenation of the strings in
<var title>set</var>, separated from each other by U+0020.
<h3>Namespaces</h3>
<p>The <dfn>HTML namespace</dfn> is
<code title>http://www.w3.org/1999/xhtml</code>.
<p>The <dfn>XML namespace</dfn> is
<code title>http://www.w3.org/XML/1998/namespace</code>.
<p>The <dfn>XMLNS namespace</dfn> is
<code title>http://www.w3.org/2000/xmlns/</code>.
<h2>Errors</h2>
<p class=XXX>This entire section will move out of DOM into IDL. <code>DOMException</code>
will be defined in terms of JavaScript and made available in both document and worker
environments. <code>DOMError</code> will go away.
<h3>Exception <code>DOMException</code></h3>
<pre class=idl>exception <dfn>DOMException</dfn> {
const unsigned short <span title=dom-DOMException-INDEX_SIZE_ERR>INDEX_SIZE_ERR</span> = 1;
const unsigned short <span title=dom-DOMException-DOMSTRING_SIZE_ERR>DOMSTRING_SIZE_ERR</span> = 2; // historical
const unsigned short <span title=dom-DOMException-HIERARCHY_REQUEST_ERR>HIERARCHY_REQUEST_ERR</span> = 3;
const unsigned short <span title=dom-DOMException-WRONG_DOCUMENT_ERR>WRONG_DOCUMENT_ERR</span> = 4;
const unsigned short <span title=dom-DOMException-INVALID_CHARACTER_ERR>INVALID_CHARACTER_ERR</span> = 5;
const unsigned short <span title=dom-DOMException-NO_DATA_ALLOWED_ERR>NO_DATA_ALLOWED_ERR</span> = 6; // historical
const unsigned short <span title=dom-DOMException-NO_MODIFICATION_ALLOWED_ERR>NO_MODIFICATION_ALLOWED_ERR</span> = 7;
const unsigned short <span title=dom-DOMException-NOT_FOUND_ERR>NOT_FOUND_ERR</span> = 8;
const unsigned short <span title=dom-DOMException-NOT_SUPPORTED_ERR>NOT_SUPPORTED_ERR</span> = 9;
const unsigned short <span title=dom-DOMException-INUSE_ATTRIBUTE_ERR>INUSE_ATTRIBUTE_ERR</span> = 10; // historical
const unsigned short <span title=dom-DOMException-INVALID_STATE_ERR>INVALID_STATE_ERR</span> = 11;
const unsigned short <span title=dom-DOMException-SYNTAX_ERR>SYNTAX_ERR</span> = 12;
const unsigned short <span title=dom-DOMException-INVALID_MODIFICATION_ERR>INVALID_MODIFICATION_ERR</span> = 13;
const unsigned short <span title=dom-DOMException-NAMESPACE_ERR>NAMESPACE_ERR</span> = 14;
const unsigned short <span title=dom-DOMException-INVALID_ACCESS_ERR>INVALID_ACCESS_ERR</span> = 15;
const unsigned short <span title=dom-DOMException-VALIDATION_ERR>VALIDATION_ERR</span> = 16; // historical
const unsigned short <span title=dom-DOMException-TYPE_MISMATCH_ERR>TYPE_MISMATCH_ERR</span> = 17; // historical; use JavaScript's TypeError instead
const unsigned short <span title=dom-DOMException-SECURITY_ERR>SECURITY_ERR</span> = 18;
const unsigned short <span title=dom-DOMException-NETWORK_ERR>NETWORK_ERR</span> = 19;
const unsigned short <span title=dom-DOMException-ABORT_ERR>ABORT_ERR</span> = 20;
const unsigned short <span title=dom-DOMException-URL_MISMATCH_ERR>URL_MISMATCH_ERR</span> = 21;
const unsigned short <span title=dom-DOMException-QUOTA_EXCEEDED_ERR>QUOTA_EXCEEDED_ERR</span> = 22;
const unsigned short <span title=dom-DOMException-TIMEOUT_ERR>TIMEOUT_ERR</span> = 23;
const unsigned short <span title=dom-DOMException-INVALID_NODE_TYPE_ERR>INVALID_NODE_TYPE_ERR</span> = 24;
const unsigned short <span title=dom-DOMException-DATA_CLONE_ERR>DATA_CLONE_ERR</span> = 25;
unsigned short <span title=dom-DOMException-code>code</span>;
};</pre>
<p>The <dfn title=dom-DOMException-code><code>code</code></dfn> exception
field must return the value it was initialized to.
<p>To <dfn title=concept-throw>throw</dfn> a <var title>name</var> exception
run these steps:
<ol>
<li><p>Let <var title>code</var> be zero.
<li><p>If <var title>name</var> is in the first column of the
<span>error names table</span> and has a corresponding legacy
<code title=dom-DOMException-code>code</code> exception field value in the
third column, set <var title>code</var> to that value.
<li><p><span data-anolis-spec=webidl>Throw</span> a new
<code>DOMException</code> exception, whose
<span data-anolis-spec=webidl>message</span> is a user agent-defined value,
<span data-anolis-spec=webidl>name</span> is <var title>name</var>, and
whose <code title=dom-DOMException-code>code</code> exception field is
<var title>code</var>.
</ol>
<p class=example>To
<i title>throw a "<code>TimeoutError</code>" exception</i>, a
user agent would construct a <code>DOMException</code> exception whose
<span data-anolis-spec=webidl>name</span> is
"<code>TimeoutError</code>" and
<code title=dom-DOMException-code>code</code> exception field value is 23,
and actually throw that object as an exception. In JavaScript, this
exception will have a <code title>name</code> property whose value is
"<code>TimeoutError</code>".
<h3>Interface <code>DOMError</code></h3>
<pre class=idl>[<span title=dom-DOMError>Constructor</span>(DOMString <var title>name</var>, optional DOMString <var title>message</var> = "")]
interface <dfn>DOMError</dfn> {
readonly attribute DOMString <span title=dom-DOMError-name>name</span>;
readonly attribute DOMString <span title=dom-DOMError-message>message</span>;
};</pre>
<p class=XXX><code>DOMError</code> will be nuked in favor of using
<code>DOMException</code> exclusively. See <a href="https://mail.mozilla.org/pipermail/es-discuss/2013-July/thread.html#31677">Creating your own errors</a>
on es-discuss for more details.
<p class=note>This interface is intended for other specifications that want
to introduce error handling through other means than exceptions. As with
exceptions, the <span>error names table</span> is used.
<p>The <dfn title=dom-DOMError><code>DOMError(<var title>name</var>, <var title>message</var>)</code></dfn>
constructor must return a new <code>DOMError</code> object whose
<code title=dom-DOMError-name>name</code> attribute is initialized to
<var title>name</var> and whose <code title=dom-DOMError-message>message</code> attribute
is initialized to <var title>message</var>.
<p>The <dfn title=dom-DOMError-name><code>name</code></dfn> attribute must
return the value it was initialized to.
<p>The <dfn title=dom-DOMError-message><code>message</code></dfn> attribute must
return the value it was initialized to.
<p class=note>The value of the <code title=dom-DOMError-message>message</code> will
typically be implementation-dependent and for informational purposes only.
<p>A
<dfn title=concept-DOMError><var title>name</var> <code>DOMError</code></dfn>
means a <code>DOMError</code> object whose
<code title=dom-DOMError-name>name</code> attribute is initialized to
<var title>name</var> and whose <code title=dom-DOMError-message>message</code> attribute
is initialized to a helpful implementation-dependent message that explains the error.
<p class=example>A specification could say that an <code title>error</code>
attribute must return a
<span title=concept-DOMError>"<code>SyntaxError</code>" <code>DOMError</code></span>.
<h3>Error names</h3>
<p>The <dfn>error names table</dfn> below lists all the allowed error names,
a description, and legacy <code title=dom-DOMException-code>code</code>
exception field values (when the error name is used for
<span title=concept-throw>throwing</span> an exception).
<p class=note>If an error name is not listed here, please file a bug as
indicated at the top of this specification and it will be addressed shortly.
Thanks!
<table id=error-names>
<thead>
<tr><th>Name<th>Description<th>Legacy <code title=dom-DOMException-code>code</code> exception field value (if any)
<tbody>
<tr>
<td>"<dfn><code>IndexSizeError</code></dfn>"
<td>The index is not in the allowed range.
<td><dfn title=dom-DOMException-INDEX_SIZE_ERR><code>INDEX_SIZE_ERR</code></dfn> (1)
<tr>
<td>"<dfn><code>HierarchyRequestError</code></dfn>"
<td>The operation would yield an incorrect <span title=concept-node-tree>node tree</span>.
<td><dfn title=dom-DOMException-HIERARCHY_REQUEST_ERR><code>HIERARCHY_REQUEST_ERR</code></dfn> (3)
<tr>
<td>"<dfn><code>WrongDocumentError</code></dfn>"
<td>The object is in the wrong <span title=concept-document>document</span>.
<td><dfn title=dom-DOMException-WRONG_DOCUMENT_ERR><code>WRONG_DOCUMENT_ERR</code></dfn> (4)
<tr>
<td>"<dfn><code>InvalidCharacterError</code></dfn>"
<td>The string contains invalid characters.
<td><dfn title=dom-DOMException-INVALID_CHARACTER_ERR><code>INVALID_CHARACTER_ERR</code></dfn> (5)
<tr>
<td>"<dfn><code>NoModificationAllowedError</code></dfn>"
<td>The object can not be modified.
<td><dfn title=dom-DOMException-NO_MODIFICATION_ALLOWED_ERR><code>NO_MODIFICATION_ALLOWED_ERR</code></dfn> (7)
<tr>
<td>"<dfn><code>NotFoundError</code></dfn>"
<td>The object can not be found here.
<td><dfn title=dom-DOMException-NOT_FOUND_ERR><code>NOT_FOUND_ERR</code></dfn> (8)
<tr>
<td>"<dfn><code>NotSupportedError</code></dfn>"
<td>The operation is not supported.
<td><dfn title=dom-DOMException-NOT_SUPPORTED_ERR><code>NOT_SUPPORTED_ERR</code></dfn> (9)
<tr>
<td>"<dfn><code>InvalidStateError</code></dfn>"
<td>The object is in an invalid state.
<td><dfn title=dom-DOMException-INVALID_STATE_ERR><code>INVALID_STATE_ERR</code></dfn> (11)
<tr>
<td>"<dfn><code>SyntaxError</code></dfn>"
<td>The string did not match the expected pattern.
<td><dfn title=dom-DOMException-SYNTAX_ERR><code>SYNTAX_ERR</code></dfn> (12)
<tr>
<td>"<dfn><code>InvalidModificationError</code></dfn>"
<td>The object can not be modified in this way.
<td><dfn title=dom-DOMException-INVALID_MODIFICATION_ERR><code>INVALID_MODIFICATION_ERR</code></dfn> (13)
<tr>
<td>"<dfn><code>NamespaceError</code></dfn>"
<td>The operation is not allowed by <cite>Namespaces in XML</cite>. <span data-anolis-ref>XMLNS</span>
<td><dfn title=dom-DOMException-NAMESPACE_ERR><code>NAMESPACE_ERR</code></dfn> (14)
<tr>
<td>"<dfn><code>InvalidAccessError</code></dfn>"
<td>The object does not support the operation or argument.
<td><dfn title=dom-DOMException-INVALID_ACCESS_ERR><code>INVALID_ACCESS_ERR</code></dfn> (15)
<tr>
<!-- XHR -->
<td>"<dfn><code>SecurityError</code></dfn>"
<td>The operation is insecure.
<td><dfn title=dom-DOMException-SECURITY_ERR><code>SECURITY_ERR</code></dfn> (18)
<tr>
<!-- XHR -->
<td>"<dfn><code>NetworkError</code></dfn>"
<td>A network error occurred.
<td><dfn title=dom-DOMException-NETWORK_ERR><code>NETWORK_ERR</code></dfn> (19)
<tr>
<!-- XHR -->
<td>"<dfn><code>AbortError</code></dfn>"
<td>The operation was aborted.
<td><dfn title=dom-DOMException-ABORT_ERR><code>ABORT_ERR</code></dfn> (20)
<tr>
<!-- Workers -->
<td>"<dfn><code>URLMismatchError</code></dfn>"
<td>The given URL does not match another URL.
<td><dfn title=dom-DOMException-URL_MISMATCH_ERR><code>URL_MISMATCH_ERR</code></dfn> (21)
<tr>
<!-- HTML -->
<td>"<dfn><code>QuotaExceededError</code></dfn>"
<td>The quota has been exceeded.
<td><dfn title=dom-DOMException-QUOTA_EXCEEDED_ERR><code>QUOTA_EXCEEDED_ERR</code></dfn> (22)
<tr>
<!-- XHR -->
<td>"<dfn><code>TimeoutError</code></dfn>"
<td>The operation timed out.
<td><dfn title=dom-DOMException-TIMEOUT_ERR><code>TIMEOUT_ERR</code></dfn> (23)
<tr>
<td>"<dfn><code>InvalidNodeTypeError</code></dfn>"
<td>The supplied node is incorrect or has an incorrect ancestor for this operation.
<td><dfn title=dom-DOMException-INVALID_NODE_TYPE_ERR><code>INVALID_NODE_TYPE_ERR</code></dfn> (24)
<tr>
<!-- HTML -->
<td>"<dfn><code>DataCloneError</code></dfn>"
<td>The object can not be cloned.
<td><dfn title=dom-DOMException-DATA_CLONE_ERR><code>DATA_CLONE_ERR</code></dfn> (25)
<tr>
<td>"<dfn><code>EncodingError</code></dfn>"
<td>The encoding operation (either encoded or decoding) failed.
<td>—
<tr>
<!-- FileAPI -->
<td>"<dfn><code>NotReadableError</code></dfn>"
<td>The <code>File</code> or <code>Blob</code> could not be read.
<td>—
</table>
<h2>Events</h2>
<h3>Introduction to "DOM Events"</h3>
<p>Throughout the web platform <span title=concept-event>events</span> are
<span title=concept-event-dispatch>dispatched</span> to objects to signal an
occurrence, such as network activity or user interaction. These objects
implement the <code>EventTarget</code> interface and can therefore add
<span title=concept-event-listener>event listeners</span> to observe
<span title=concept-event>events</span>:
<pre><code>obj.addEventListener("load", imgFetched)
function imgFetched(ev) {
// great success
…
}</code></pre>
<p><span title=concept-event-listener>Event listeners</span> can be removed
by utilizing the
<code title=dom-EventTarget-removeEventListener>removeEventListener()</code>
method, passing the same arguments.
<p><span title=concept-event>Events</span> are objects too and implement the
<code>Event</code> interface (or a derived interface). In the example above
<var title>ev</var> is the <span title=concept-event>event</span>. It is
passed as argument to
<span title=concept-event-listener>event listener</span>'s <b>callback</b>
(typically a JavaScript Function as shown above).
<span title=concept-event-listener>Event listeners</span> key off the
<span title=concept-event>event</span>'s
<code title=dom-Event-type>type</code> attribute value
("<code title>load</code>" in the above example). The
<span title=concept-event>event</span>'s
<code title=dom-Event-target>target</code> attribute value returns the
object to which the <span title=concept-event>event</span> was
<span title=concept-event-dispatch>dispatched</span> (<var title>obj</var>
above).
<p>Now while typically <span title=concept-event>events</span> are
<span title=concept-event-dispatch>dispatched</span> by the user agent as
the result of user interaction or the completion of some task, applications
can <span title=concept-event-dispatch>dispatch</span>
<span title=concept-event>events</span> themselves, commonly known as
synthetic events:
<pre><code>// add an appropriate event listener
obj.addEventListener("cat", function(e) { process(e.detail) })
// create and dispatch the event
var event = new CustomEvent("cat", {"detail":{"hazcheeseburger":true}})
obj.dispatchEvent(event)</code></pre>
<p>Apart from signaling, <span title=concept-event>events</span> are
sometimes also used to let an application control what happens next in an
operation. For instance as part of form submission an
<span title=concept-event>event</span> whose
<code title=dom-Event-type>type</code> attribute value is
"<code title>submit</code>" is
<span title=concept-event-dispatch>dispatched</span>. If this
<span title=concept-event>event</span>'s
<code title=dom-Event-preventDefault>preventDefault()</code> method is
invoked, form submission will be terminated. Applications who wish to make
use of this functionality through <span title=concept-event>events</span>
<span title=concept-event-dispatch>dispatched</span> by the application
(synthetic events) can make use of the return value of the
<code title=dom-EventTarget-dispatchEvent>dispatchEvent()</code> method:
<pre><code>if(obj.dispatchEvent(event)) {
// event was not canceled, time for some magic
…
}</code></pre>
<p>When an <span title=concept-event>event</span> is
<span title=concept-event-dispatch>dispatched</span> to an object that
<span title=concept-tree-participate>participates</span> in a
<span title=concept-tree>tree</span> (e.g. an
<span title=concept-element>element</span>), it can reach
<span title=concept-event-listener>event listeners</span> on that object's
<span title=concept-tree-ancestor>ancestors</span> too. First all object's
<span title=concept-tree-ancestor>ancestor</span>
<span title=concept-event-listener>event listeners</span> whose
<b>capture</b> variable is set to true are invoked, in
<span title=concept-tree-order>tree order</span>. Second, object's own
<span title=concept-event-listener>event listeners</span> are invoked. And
finally, and only if <span title=concept-event>event</span>'s
<span title=dom-Event-bubbles>bubbles</span> attribute value is true,
object's <span title=concept-tree-ancestor>ancestor</span>
<span title=concept-event-listener>event listeners</span> are invoked again,
but now in reverse <span title=concept-tree-order>tree order</span>.
<p>Lets look at an example on how <span title=concept-event>events</span>
work in a <span title=concept-tree>tree</span>:
<pre><code><!doctype html>
<html>
<head>
<title>Boring example</title>
</head>
<body>
<p>Hello <span id=x>world</span>!</p>
<script>
function test(e) {
debug(e.target, e.currentTarget, e.eventPhase)
}
document.addEventListener("hey", test, true)
document.body.addEventListener("hey", test)
var ev = new Event("hey", {bubbles:true})
document.getElementById("x").dispatchEvent(ev)
</script>
</body>
</html></code></pre>
<p>The <code title>debug</code> function will be invoked twice. Each time
the <span title=concept-event>events</span>'s
<code title=dom-Event-target>target</code> attribute value will be the
<code title>span</code> <span title=concept-element>element</span>. The
first time <code title=dom-Event-target>currentTarget</code> attribute's
value will be the <span title=concept-document>document</span>, the second
time the <code title>body</code> <span title=concept-element>element</span>.
<code title=dom-Event-eventPhase>eventPhase</code> attribute's value
switches from <code title=dom-Event-CAPTURING_PHASE>CAPTURING_PHASE</code>
to <code title=dom-Event-BUBBLING_PHASE>BUBBLING_PHASE</code>. If an
<span title=concept-event-listener>event listener</span> was registered for
the <code title>span</code> <span title=concept-element>element</span>,
<code title=dom-Event-eventPhase>eventPhase</code> attribute's value
would have been <code title=dom-Event-AT_TARGET>AT_TARGET</code>.
<h3>Interface <code>Event</code></h3>
<pre class="idl">[<span title=concept-event-constructor>Constructor</span>(DOMString <var title>type</var>, optional <span>EventInit</span> <var title>eventInitDict</var>),
Exposed=Window,Worker]
interface <dfn>Event</dfn> {
readonly attribute DOMString <span title=dom-Event-type>type</span>;
readonly attribute <span>EventTarget</span>? <span title=dom-Event-target>target</span>;
readonly attribute <span>EventTarget</span>? <span title=dom-Event-currentTarget>currentTarget</span>;
const unsigned short <span title=dom-Event-NONE>NONE</span> = 0;
const unsigned short <span title=dom-Event-CAPTURING_PHASE>CAPTURING_PHASE</span> = 1;
const unsigned short <span title=dom-Event-AT_TARGET>AT_TARGET</span> = 2;
const unsigned short <span title=dom-Event-BUBBLING_PHASE>BUBBLING_PHASE</span> = 3;
readonly attribute unsigned short <span title=dom-Event-eventPhase>eventPhase</span>;
void <span title=dom-Event-stopPropagation>stopPropagation</span>();
void <span title=dom-Event-stopImmediatePropagation>stopImmediatePropagation</span>();
readonly attribute boolean <span title=dom-Event-bubbles>bubbles</span>;
readonly attribute boolean <span title=dom-Event-cancelable>cancelable</span>;
void <span title=dom-Event-preventDefault>preventDefault</span>();
readonly attribute boolean <span title=dom-Event-defaultPrevented>defaultPrevented</span>;
[Unforgeable] readonly attribute boolean <span title=dom-Event-isTrusted>isTrusted</span>;
readonly attribute DOMTimeStamp <span title=dom-Event-timeStamp>timeStamp</span>;
void <span title=dom-Event-initEvent>initEvent</span>(DOMString <var title>type</var>, boolean <var title>bubbles</var>, boolean <var title>cancelable</var>);
};
dictionary <dfn>EventInit</dfn> {
boolean <span title=dom-EventInit-bubbles>bubbles</span> = false;
boolean <span title=dom-EventInit-cancelable>cancelable</span> = false;
};</pre>
<p>An <dfn title=concept-event>event</dfn> allows for signaling that
something has occurred. E.g. that an image has completed downloading. It is
represented by the <code>Event</code> interface or an interface that
inherits from the <code>Event</code> interface.</p>
<dl class=domintro>
<dt><code>var <var title>event</var> = new <span title=concept-event-constructor>Event</span>(<var title>type</var> [, <var title>eventInitDict</var>])</code>
<dd><p>Returns a new <var title>event</var> whose
<code title=dom-Event-type>type</code> attribute value is set to
<var title>type</var>. The optional <var title>eventInitDict</var> argument
allows for setting the <code title=dom-Event-bubbles>bubbles</code> and
<code title=dom-Event-cancelable>cancelable</code> attributes via object
members of the same name.
<dt><code><var title>event</var> . <span title=dom-Event-type>type</span></code>
<dd><p>Returns the type of <var title>event</var>, e.g.
"<code title>click</code>", "<code title>hashchange</code>", or
"<code title>submit</code>".
<dt><code><var title>event</var> . <span title=dom-Event-target>target</span></code>
<dd><p>Returns the object <var title>event</var> is
<span title=concept-event-dispatch>dispatched</span> to.
<dt><code><var title>event</var> . <span title=dom-Event-currentTarget>currentTarget</span></code>
<dd><p>Returns the object whose
<span title=concept-event-listener>event listener</span>'s <b>callback</b>
is invoked.
<dt><code><var title>event</var> . <span title=dom-Event-eventPhase>eventPhase</span></code>
<dd><p>Returns the <span title=concept-event>event</span>'s phase, which is
one of <code title=dom-Event-NONE>NONE</code>,
<code title=dom-Event-CAPTURING_PHASE>CAPTURING_PHASE</code>,
<code title=dom-Event-AT_TARGET>AT_TARGET</code>, and
<code title=dom-Event-BUBBLING_PHASE>BUBBLING_PHASE</code>.
<dt><code><var title>event</var> . <span title=dom-Event-stopPropagation>stopPropagation</span>()</code>
<dd><p>When <span title=concept-event-dispatch>dispatched</span> in a
<span title=concept-tree>tree</span>, invoking this method prevents
<var title>event</var> from reaching any other objects than the current.
<dt><code><var title>event</var> . <span title=dom-Event-stopImmediatePropagation>stopImmediatePropagation</span>()</code>
<dd><p>Invoking this method prevents <var title>event</var> from reaching
any <span title=concept-event-listener>event listeners</span> registered
after the current one and when
<span title=concept-event-dispatch>dispatched</span> in a
<span title=concept-tree>tree</span> also prevents
<var title>event</var> from reaching any other objects.
<dt><code><var title>event</var> . <span title=dom-Event-bubbles>bubbles</span></code>
<dd><p>Returns true if <var title>event</var>'s goes through its <code title=dom-Event-target>target</code> attribute value's <span title=concept-tree-ancestor>ancestors</span> in reverse <span title=concept-tree-order>tree order</span>, and false otherwise.
<dt><code><var title>event</var> . <span title=dom-Event-cancelable>cancelable</span></code>
<dd><p>Returns true or false depending on how <var title>event</var> was
initialized. Its return value does not always carry meaning, but true can
indicate that part of the operation during which <var title>event</var> was
<span title=concept-event-dispatch>dispatched</span>, can be canceled by
invoking the <code title=dom-Event-preventDefault>preventDefault()</code>
method.
<dt><code><var title>event</var> . <span title=dom-Event-preventDefault>preventDefault</span>()</code>
<dd><p>If invoked when the
<code title=dom-Event-cancelable>cancelable</code> attribute value is true,
signals to the operation that caused <var title>event</var> to be
<span title=concept-event-dispatch>dispatched</span> that it needs to be
canceled.
<dt><code><var title>event</var> . <span title=dom-Event-defaultPrevented>defaultPrevented</span></code>
<dd><p>Returns true if
<code title=dom-Event-preventDefault>preventDefault()</code> was invoked
while the <code title=dom-Event-cancelable>cancelable</code> attribute
value is true, and false otherwise.
<dt><code><var title>event</var> . <span title=dom-Event-isTrusted>isTrusted</span></code>
<dd><p>Returns true if <var title>event</var> was
<span title=concept-event-dispatch>dispatched</span> by the user agent, and
false otherwise.
<dt><code><var title>event</var> . <span title=dom-Event-timeStamp>timeStamp</span></code>
<dd><p>Returns the creation time of <var title>event</var> in the number of
milliseconds that passed since 00:00:00 UTC on 1 January 1970.
<!-- initEvent is dead -->
</dl>
<p>The <dfn title=dom-Event-type><code>type</code></dfn> attribute must
return the value it was initialized to. When an
<span title=concept-event>event</span> is created the attribute must be
initialized to the empty string.
<p>The <dfn title=dom-Event-target><code>target</code></dfn> and
<dfn title=dom-Event-currentTarget><code>currentTarget</code></dfn>
attributes must return the values they were initialized to. When an
<span title=concept-event>event</span> is created the attributes must be
initialized to null.
<p>The <dfn title=dom-Event-eventPhase><code>eventPhase</code></dfn>
attribute must return the value it was initialized to, which must be one of
the following:</p>
<dl>
<dt><dfn title=dom-Event-NONE><code>NONE</code></dfn> (numeric value 0)
<dd><p><span title=concept-event>Events</span> not currently
<span title=concept-event-dispatch>dispatched</span> are in this phase.
<dt><dfn title=dom-Event-CAPTURING_PHASE><code>CAPTURING_PHASE</code></dfn> (numeric value 1)</dt>
<dd><p>When an <span title=concept-event>event</span> is
<span title=concept-event-dispatch>dispatched</span> to an object that
<span title=concept-tree-participate>participates</span> in a
<span title=concept-tree>tree</span> it will be in this phase before it
reaches its <code title=dom-Event-target>target</code> attribute value.
<dt><dfn title=dom-Event-AT_TARGET><code>AT_TARGET</code></dfn> (numeric value 2)
<dd><p>When an <span title=concept-event>event</span> is
<span title=concept-event-dispatch>dispatched</span> it will be in this
phase on its <code title=dom-Event-target>target</code> attribute value.
<dt><dfn title=dom-Event-BUBBLING_PHASE><code>BUBBLING_PHASE</code></dfn> (numeric value 3)
<dd><p>When an <span title=concept-event>event</span> is
<span title=concept-event-dispatch>dispatched</span> to an object that
<span title=concept-tree-participate>participates</span> in a
<span title=concept-tree>tree</span> it will be in this phase after it
reaches its <code title=dom-Event-target>target</code> attribute value.
</dl>
<p>Initially the attribute must be initialized to
<code title=dom-Event-NONE>NONE</code>.
<hr>
<p>Each <span title=concept-event>event</span> has the following associated
flags that are all initially unset:</p>
<ul>
<li><dfn>stop propagation flag</dfn>
<li><dfn>stop immediate propagation flag</dfn>
<li><dfn>canceled flag</dfn>
<li><dfn>initialized flag</dfn>
<li><dfn>dispatch flag</dfn>
</ul>
<p>The
<dfn title=dom-Event-stopPropagation><code>stopPropagation()</code></dfn>
method must set the <span>stop propagation flag</span>.
<p>The
<dfn title=dom-Event-stopImmediatePropagation><code>stopImmediatePropagation()</code></dfn>
method must set both the <span>stop propagation flag</span> and
<span>stop immediate propagation flag</span>.
<p>The <dfn title=dom-Event-bubbles><code>bubbles</code></dfn> and
<dfn title=dom-Event-cancelable><code>cancelable</code></dfn> attributes
must return the values they were initialized to. When an
<span title=concept-event>event</span> is created, they must be initialized
to false. <span class=note>The <code>EventInit</code> dictionary is not sufficient due to
the existence of the legacy
<code title=dom-Document-createEvent>createEvent()</code>.</span>
<p>The
<dfn title=dom-Event-preventDefault><code>preventDefault()</code></dfn>
method must set the <span>canceled flag</span> if the
<code title=dom-Event-cancelable>cancelable</code> attribute value is true.
<p>The
<dfn title=dom-Event-defaultPrevented><code>defaultPrevented</code></dfn>
attribute must return true if the <span>canceled flag</span> is set and
false otherwise.
<hr>
<p>The <dfn title=dom-Event-isTrusted><code>isTrusted</code></dfn> attribute
must return the value it was initialized to. When an
<span title=concept-event>event</span> is created the attribute must be
initialized to false.
<p>The <dfn title=dom-Event-timeStamp><code>timeStamp</code></dfn> attribute
must return the value it was initialized to. When an
<span title=concept-event>event</span> is created the attribute must be
initialized to the number of milliseconds that have passed since
00:00:00 UTC on 1 January 1970, ignoring leap seconds.
<!-- leap seconds are ignored by JavaScript too -->
<hr>
<p>To <dfn title=concept-event-initialize>initialize</dfn> an
<var title>event</var>, with <var title>type</var>,
<var title>bubbles</var>, and <var title>cancelable</var>, run these steps:
<ol>
<li><p>Set the <span>initialized flag</span>.
<li><p>If the <span>dispatch flag</span> is set, terminate these steps.
<li><p>Unset the <span>stop propagation flag</span>,
<span>stop immediate propagation flag</span>, and
<span>canceled flag</span>.
<li><p>Set the <code title=dom-Event-isTrusted>isTrusted</code> attribute
to false.
<li><p>Set the <code title=dom-Event-target>target</code> attribute to
null.
<li><p>Set the <code title=dom-Event-type>type</code> attribute to
<var title>type</var>.
<li><p>Set the <code title=dom-Event-bubbles>bubbles</code> attribute to
<var title>bubbles</var>.
<li><p>Set the <code title=dom-Event-cancelable>cancelable</code> attribute
to <var title>cancelable</var>.
</ol>
<p>The
<dfn title=dom-Event-initEvent><code>initEvent(<var title>type</var>, <var title>bubbles</var>, <var title>cancelable</var>)</code></dfn>
method must <span title=concept-event-initialize>initialize</span> the
<span>context object</span> with <var title>type</var>,
<var title>bubbles</var>, and <var title>cancelable</var>.
<p class=note>As <span title=concept-event>events</span> have constructors
<code title=dom-Event-initEvent>initEvent()</code> is superfluous. However,
it has to be supported for legacy content.
<h3>Interface <code>CustomEvent</code></h3>
<pre class=idl>[<span title=concept-event-constructor>Constructor</span>(DOMString <var title>type</var>, optional <span>CustomEventInit</span> <var title>eventInitDict</var>),
Exposed=Window,Worker]
interface <dfn>CustomEvent</dfn> : <span>Event</span> {
readonly attribute any <span title=dom-CustomEvent-detail>detail</span>;
void <span title=dom-CustomEvent-initCustomEvent>initCustomEvent</span>(DOMString <var title>type</var>, boolean <var title>bubbles</var>, boolean <var title>cancelable</var>, any <var title>detail</var>);
};
dictionary <dfn>CustomEventInit</dfn> : <span>EventInit</span> {
any <span title=dom-CustomEventInit-detail>detail</span> = null;
};</pre>
<p><span title=concept-event>Events</span> using the
<code>CustomEvent</code> interface can be used to carry custom data.</p>
<dl class=domintro>
<dt><code>var <var title>event</var> = new <span title=concept-event-constructor>CustomEvent</span>(<var title>type</var> [, <var title>eventInitDict</var>])</code>
<dd><p>Works analogously to the constructor for <code>Event</code> except
that the optional <var title>eventInitDict</var> argument now
allows for setting the <code title=dom-Event-detail>detail</code> attribute
too.
<dt><code><var title>event</var> . <span title=dom-CustomEvent-detail>detail</span></code>
<dd><p>Returns any custom data <var title>event</var> was created with.
Typically used for synthetic events.
<!-- initCustomEvent is dead -->
</dl>
<p>The <dfn title=dom-CustomEvent-detail><code>detail</code></dfn> attribute
must return the value it was initialized to. When an
<span title=concept-event>event</span> is created the attribute must be
initialized to null. <span class=note>The <code>CustomEventInit</code> dictionary is not
sufficient due to the existence of the legacy
<code title=dom-Document-createEvent>createEvent()</code>.</span>
<p>The
<dfn title=dom-CustomEvent-initCustomEvent><code>initCustomEvent(<var title>type</var>, <var title>bubbles</var>, <var title>cancelable</var>, <var title>detail</var>)</code></dfn>