Modify ↓
Ticket #3 (closed bug: fixed)
DOM insertion methods fail on elements that have a length property
| Reported by: | Klaus Hartl | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.0 |
| Component: | core | Version: | 1.0 |
| Keywords: | dom insertion | Cc: | |
| Blocking: | Blocked by: |
Description
The DOM insertion methods append/prepend/before/after fail on elements that have a length property, like a form or text node:
The problem lies in $.clean, proposed fix (tested):
$.clean = function(a) {
var r = [];
for ( var i = 0; i < a.length; i++ )
if ( a[i].constructor == String ) {
var div = document.createElement("div");
div.innerHTML = a[i];
for ( var j = 0; j < div.childNodes.length; j++ )
r[r.length] = div.childNodes[j];
} else if ( a[i].length && !a[i].nodeType ) // added fix for nodes with length property (form, text node)
for ( var j = 0; j < a[i].length; j++ )
r[r.length] = a[i][j];
else if ( a[i] != null )
r[r.length] =
a[i].nodeType ? a[i] : document.createTextNode(a[i].toString());
return r;
};
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

Fixed in SVN #78. Thanks for the find, Klaus!