[jQuery] Recent breakage in $().append()

[jQuery] Recent breakage in $().append()


I'm really enjoying JQuery, though it's a bit of a challenge programming to
a moving target with all this innovation going on! :-) The code in .append()
used to read:
for ( var i in a )
if ( a[i].cloneNode )
this.appendChild( a[i].cloneNode(true) );
Now with the recent cloneNode change it reads:
for ( var i in a )
this.appendChild( clone ? a[i].cloneNode(true) : a[i] );
I add some methods to the Array object. In the older version the check for a
cloneNode method prevented these methods from being appended. With that
missing now, the new code tries to insert them into the tree--badness. I
think this would fix it:
for ( var i = 0; i < a.length; i++ )
this.appendChild( clone ? a[i].cloneNode(true) : a[i] );
Notice that this is still a behavioral change from the older version,
though. For a case like $(body).append(34) the old code would silently do
nothing; the new code will throw an error. That seems wrong though, I think
it should just create a text node. So I'd also propose this change to
$.clean() as a fix:
- else
- r[r.length] = a[i];
+ else
+ r[r.length] =
+ a[i].nodeType? a[i] : document.createTextNode(a[i].toString());
Here I'm using nodeType as an indicator that it's a DOM node--is there a
better way? This lets you pass just about any object type (Number, Date,
RegExp, Boolean) and it will be converted to a text node with no extra fuss.
Also, should $.clean remove null arguments?
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/