Skip to content

Conversation

Rob-pw
Copy link

@Rob-pw Rob-pw commented Jun 12, 2015

At present, calling insertNodeAtPosition where n is a void element (e.g., <br>) causes the element to be appended as a child element, which results (potentially) in invalid nested elements.

I have added an array containing all the void elements as per http://www.w3.org/TR/html-markup/syntax.html#void-elements, and a function canAppendChild(element) to avoid this issue.

@timdown
Copy link
Owner

timdown commented Jun 13, 2015

I like this conceptually, but I'm not sure whether it is the correct thing to do. Current versions of all the major browsers allow you to add child nodes to a <br> element via JavaScript, both directly and using Range.insertNode. If you do so, the content shows up in the childNodes property of the <br> element but is not rendered and does not show up in innerHTML. I would guess this behaviour is specified somewhere since all the browsers do it. I'll try to find out.

@Rob-pw
Copy link
Author

Rob-pw commented Jun 16, 2015

You are correct, elements can be appended to void elements, however they are not rendered. If changing existing functionality is undesirable, maybe just expose a method for checking whether an element can be appended as a child, that would satisfy my requirements also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants