Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#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:
Blocked by: Blocking:

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;
};

See http://jquery.com/discuss/2006-May/000804/

Change History (1)

comment:1 Changed 11 years ago by john

  • Resolution set to fixed
  • Status changed from new to closed

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

Note: See TracTickets for help on using tickets.