-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ParentNode.prototype.replaceContents(nodes) #755
Add ParentNode.prototype.replaceContents(nodes) #755
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for starting on this so quickly! I think this needs a slightly different approach, which I've tried to outline inline. Basically what I'd like to see is for this to build upon the same primitive innerHTML
and textContent
use, but it'll need some additional checks as the input isn't necessary restricted to Text and Element nodes as it is with those APIs.
@@ -2839,6 +2839,7 @@ interface mixin ParentNode { | |||
|
|||
[CEReactions, Unscopable] void prepend((Node or DOMString)... nodes); | |||
[CEReactions, Unscopable] void append((Node or DOMString)... nodes); | |||
[CEReactions, Unscopable] void replaceContents((Node or DOMString)... nodes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think per the discussion we ended up with replaceChildren()
as a name, as "contents" doesn't always refer to nodes. Did I miss something?
@@ -2878,6 +2879,15 @@ Element includes ParentNode; | |||
the <a>node tree</a> are violated. | |||
<!-- "NotFoundError" is impossible --> | |||
|
|||
<dt><code><var>node</var> . <a method for=ParentNode lt="replaceContents()">replaceContents</a>(<var>nodes</var>)</code> | |||
<dd> | |||
<p>Inserts <var>nodes</var> after the <a>last child</a> of <var>node</var>, while replacing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs rewording.
<li><a for=/>Remove</a> all | ||
<var>parent</var>'s <a>children</a>, in | ||
<a>tree order</a>, with the | ||
<i>suppress observers flag</i> set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should strive to use the https://dom.spec.whatwg.org/#concept-node-replace-all primitive here, which would take care of most of the work, preceded by a call to https://dom.spec.whatwg.org/#converting-nodes-into-a-node.
And I guess we need to run https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity as well.
I intend to make corrections next week. Thanks for the great feedback, and also for getting it back to me so quickly. |
Tests: web-platform-tests/wpt#22524 Fixes #478. Closes #755 and closes #835.
Tests: web-platform-tests/wpt#22524 Fixes whatwg#478. Closes whatwg#755 and closes whatwg#835.
The ParentNode.replaceContents() method would remove all child nodes from the ParentNode while allowing the insertion of a new set of nodes.
Resolves #478