views:

177

answers:

2

Today I stumbled on createDocumentFragment. I was wondering if the DocumementFragment is supported, and how, on the different browsers, expecially IE series.

Anyone knows anything about this subject?

+1  A: 

Yep, it's fully supported in all modern browsers (including IE6).

See: http://www.quirksmode.org/dom/w3c%5Fcore.html#miscellaneous

J-P
Even though documentFragment is supported by all browsers, the DOM traversal methods like `getElementsByTagName`, `children`, etc. do not work on them.
Livingston Samuel
+1  A: 

In general it has always worked fine as per the DOM spec.

But don't expect non-standard extensions to work seamlessly... for example you can't set innerHTML on a DocumentFragment (which is a shame as it could have greatly improved insertion speed on some large pages).

bobince
but you can create a holder `div` with `document.createElement` and add the string as `innerHTML` to the `div`, and then finally append the `div` to the `documentFragment`
Livingston Samuel
Yes, but that gives no performance advantage over just operating directly on the `div`. The idea would be to speed up operations like adding many rows to a table, that are typically slow with node-by-node DOM methods. You can do a lot of this by combining fragments with `Range` objects, except that browser implementations of DOM Level 2 TR (especially IE's) aren't completely there yet.
bobince