#212 enhancement
Ted Kaminski

Improved XHTML support

Reported by Ted Kaminski | July 9th, 2008 @ 04:40 AM

I've been using Prototype extensively with a project that's done with strict XHTML (served as application/xml+xhtml), which means .innerHTML does not (or should not) work.

We've found a small number of changes to Prototype to be extremely helpful when working under these conditions:

1. The DOM builder is excellent, but it lacks support for one very important type of node: text nodes! A shortcut like $T that's just a wrapper around document.createTextNode is extremely useful, as creating text nodes manually is necessary in a world with no .innerHTML.

2. For #3 below, we needed a new function for all elements: removeChildren. This just deletes all child nodes the DOM way:

removeChildren: function (element) {
  while(element.firstChild)
    element.removeChild(element.firstChild);
}

3. Element.update() of course will not work with strings, but it needlessly refuses to work with DOM objects. This change to that function fixes it:

// Old:
if (Object.isElement(content)) return element.update().insert(content);
// New:
if (Object.isElement(content)) return element.removeChildren().insert(content);

This is mostly just a feature request, though I suppose #3 qualifies as a bug report: it's impossible to update the text of a node via Prototype without it, .down() ignores text nodes so you can't even .down().replace($T("new text"))!

Comments and changes to this ticket

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket