diff --git a/source b/source index 4fb108dcfe6..e51078951fb 100644 --- a/source +++ b/source @@ -1772,10 +1772,9 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute or string, means that the length of the text is zero (i.e., not even containing controls or U+0020 SPACE).
-An HTML element can have specific HTML element insertion steps defined for the - element's local name. Similarly, an HTML element - can have specific HTML element removing steps defined for the element's local name.
+An HTML element can have specific HTML element insertion steps, HTML element + post-connection steps, and HTML element removing steps, all defined for the + element's local name.
The insertion steps for the HTML Standard, given insertedNode, are defined as the following:
@@ -1806,6 +1805,18 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute node document. +The post-connection steps for the HTML + Standard, given insertedNode, are defined as the following:
+ +If insertedNode is an element whose namespace is the HTML namespace, and this + standard defines HTML element post-connection + steps for insertedNode's local + name, then run the corresponding HTML element post-connection steps given + insertedNode.
The removing steps for the HTML Standard, given removedNode and oldParent, are defined as the following:
@@ -3204,6 +3215,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attributecreateElementNS()
methodgetElementById()
methodgetElementsByClassName()
methodappend()
methodappendChild()
methodcloneNode()
methodimportNode()
methodWhen a script
element el that is not parser-inserted
- experiences one of the events listed in the following list, the user agent must
- immediately prepare the script element el:
The script
HTML element post-connection steps, given
+ insertedNode, are:
script
element becomes connected.If insertedNode is not connected, then return.
-script
element is connected and a node or document fragment is
- inserted into the script
element,
- after any script
elements inserted
- at that time.This can happen in the case where an earlier-inserted script
removes a
+ later-inserted script
. For instance:
script
element is connected and has a src
attribute set where previously the element had no such
- attribute.<script>
+const script1 = document.createElement('script');
+script1.innerText = `
+ document.querySelector('#script2').remove();
+`;
+
+const script2 = document.createElement('script');
+script2.id = 'script2';
+script2.textContent = `console.log('script#2 running')`;
+
+document.body.append(script1, script2);
+</script>
+
+ Nothing is printed to the console in this example. By the time the HTML element
+ post-connection steps run for the first script
that was atomically inserted
+ by append()
, it can observe that the second
+ script
is already connected to the DOM. It removes the second
+ script
, so that by the time its HTML element post-connection
+ steps run, it is no longer connected, and does not get prepared.
If insertedNode is parser-inserted, then return.
Prepare the script element given insertedNode.
The script
children changed steps are:
Run the script
HTML element post-connection steps, given the
+ script
element.
This has an interesting implication on the execution order of a script
element
+ and any newly-inserted child script
elements. Consider the following snippet:
<script id=outer-script></script>
+
+<script>
+ const outerScript = document.querySelector('#outer-script');
+
+ const start = new Text('console.log(1);');
+ const innerScript = document.createElement('script');
+ innerScript.textContent = `console.log('inner script executing')`;
+ const end = new Text('console.log(2);');
+
+ outerScript.append(start, innerScript, end);
+
+ // Logs:
+ // 1
+ // 2
+ // inner script executing
+</script>
+
+ By the time the second script block executes, the outer-script
has
+ already been prepared, but because it is empty,
+ it did not execute and therefore is not marked as already started. The atomic
+ insertion of the Text
nodes and nested script
element have the
+ following effects:
All three child nodes get atomically inserted as children of outer-script
; all of their insertion
+ steps run, which have no observable consequences in this case.
The outer-script
's children changed steps run, which
+ prepares that script; because its body is now
+ non-empty, this executes the contents of the two Text
nodes, in order.
The script
HTML element post-connection steps finally run for
+ innerScript
, causing its body to execute.
The following attribute change
+ steps, given element, localName, oldValue,
+ value, and namespace, are used for all script
elements:
If namespace is not null, then return.
If localName is src
, then run the
+ script
HTML element post-connection steps, given
+ element.
To prepare the script element given a script
element el: