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 12584 - outerHTML should probably merge with adjacent text nodes if applicable. IE seems to do this to some extent, and WebKit just changed to do it: <https://bugs.webkit.org/show_bug.cgi?id=52686> This test shows behavior for outerText and outerHTML: <http://so
Summary: outerHTML should probably merge with adjacent text nodes if applicable. IE s...
Status: NEW
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM Parsing and Serialization (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: ---
Assignee: Travis Leithead [MSFT]
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on: 11204
Blocks:
  Show dependency treegraph
 
Reported: 2011-05-02 22:41 UTC by contributor
Modified: 2015-10-02 01:23 UTC (History)
12 users (show)

See Also:


Attachments

Description contributor 2011-05-02 22:41:40 UTC
Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/apis-in-html-documents.html
Section: http://www.whatwg.org/specs/web-apps/current-work/#outerhtml

Comment:
outerHTML should probably merge with adjacent text nodes if applicable.  IE
seems to do this to some extent, and WebKit just changed to do it:
<https://bugs.webkit.org/show_bug.cgi?id=52686> This test shows behavior for
outerText and outerHTML:
<http://software.hixie.ch/utilities/js/live-dom-viewer/saved/971> (Opera never
merges, IE9 merges for outerText and partially merges for outerHTML, WebKit
now fully merges for both, Gecko doesn't implement either)

Posted from: 68.175.61.233
User agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.12 Safari/534.30
Comment 1 Michael[tm] Smith 2011-08-04 05:17:30 UTC
mass-move component to LC1
Comment 2 Arkadiusz Michalski (Spirit) 2015-10-01 18:55:47 UTC
If it is taken into account then analyze more tescase, because for IE I noticed different behaviour (depending on how the tree was constructed).

<script>

	var container = document.createElement("div");
	container.appendChild(document.createTextNode("Text node 1"));
	container.appendChild(document.createTextNode("Text node 2"));
	
	var newEl = document.createElement("div");
	newEl.textContent = "Element content";
	container.appendChild(newEl);
	
	container.appendChild(document.createTextNode("Text node 3"));
	container.appendChild(document.createTextNode("Text node 4"));
	
	alert(container.childNodes.length);
	
	container.childNodes[2].outerHTML = " outerHTML ";
	
	alert(container.childNodes.length);
	alert(container.childNodes[1].data);

</script>

Firefox, Opera (Presto) alerts: 5, 5, Text node 2 << not merge anything

Chrome alerts: 5, 3, Text node 2 outerHTML Text node 3 << merge previous and next sibling (only text node) if exist

IE11 alerts: 5, 4, Text node 2 outerHTML << merge previous sibling (only text node) if exist, but if not exist and exist next sibling (only text node) then merge with them. This is not the same what we see in example from comment0.

But if merge will became standarized then what merge, only previous and next sibling (text node) or all contiguous Text nodes (https://dom.spec.whatwg.org/#contiguous-text-nodes)?
Comment 3 Arkadiusz Michalski (Spirit) 2015-10-02 01:23:55 UTC
One more thing, IE11 also merge text nodes for Element.insertAdjacentHTML(), but Chrome and Firefox no.

<script type = "text/javascript">

	var container = document.createElement("div");
	container.appendChild(document.createTextNode("Text node 1"));
	container.appendChild(document.createTextNode("Text node 2"));
	container.appendChild(document.createElement("div"));
	
	container.childNodes[2].insertAdjacentHTML("beforebegin", " Parsed text");
	alert(container.childNodes.length);
	alert(container.childNodes[1].data);

</script>

Firefox, Chrome alerts: 4, Text node 2
IE11 alerts: 3, Text node 2 Parsed text

I'm opposite for merging text node in all this cases, they change node tree without possibility of control this behaviour. If someone want clean up tree then can use Node.normalize() or other way (how he want). There is no need to complicate this more.