Skip to content

Should the innerHTML of void elements include child nodes? #4220

@Zirro

Description

@Zirro

The following test case produces different results in Edge/Firefox and Chrome/Safari:

<!DOCTYPE html>

<script>
const voidEl = document.createElement("br");
voidEl.appendChild(document.createElement("p")).textContent = "Hello Void!";

console.log(voidEl.innerHTML);
</script>

Live DOM Viewer

Edge and Firefox will serialize the child nodes of the void element and log <p>Hello Void!</p>, while Chrome and Safari will log the empty string.

The algorithm used by innerHTML, Serializing HTML fragments, does contain a step where the children of void elements are skipped. However, it only applies to the child nodes of the node given as input whereas if the node given as input is itself a void element, it is not handled differently from non-void elements.

Edge and Firefox appear to be consistent with the specification as it's currently written, but given the differing implementations it may be worth considering whether the child nodes of void elements should be serialized at all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    interopImplementations are not interoperable with each othertopic: parser

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions