This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 12389 - replaceWholeText should not remove the context node, just change its data
Summary: replaceWholeText should not remove the context node, just change its data
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: All All
: P2 minor
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-28 17:41 UTC by Aryeh Gregor
Modified: 2011-09-07 13:06 UTC (History)
2 users (show)

See Also:


Attachments

Description Aryeh Gregor 2011-03-28 17:41:35 UTC
The current spec says

"""
The replaceWholeText(data) method must run these steps:

  1. Remove the contiguous Text nodes of the context object.

  2. If data is not the empty string, insert a new Text node whose data is data at the place of the removed nodes, return the new Text node, and then terminate these steps.

  3. Return null.
"""

But in fact browsers don't remove the node itself, they only remove siblings.  Test case:

data:text/html,<!doctype html>
<p>Abc</p>
<script>
var original = document.querySelector("p").firstChild;
document.body.textContent = original.replaceWholeText("Def") == original;
</script>

Results in "true" in Firefox 4.0, Chrome 11 dev, and Opera 11.  (I didn't have IE available for easy testing.)  The spec should say that if data is not the empty string, the contiguous Text nodes of the context objects must be removed except for the context object itself, then the context object's data should be set and the method should return the context object.