Bug Tracker

Modify

Ticket #3 (closed bug: fixed)

Opened 7 years ago

Last modified 6 years ago

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

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

Change History

comment:1 Changed 7 years ago by john

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

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.