NOT_FOUND_ERROR when using the text() method.
I'm seeing something truly bizarre, after upgrading to jQuery 1.5.1
SO thread here:
Basically, at certain points of my app, I am getting a
NOT_FOUND_ERR: DOM Exception 8:
An attempt was made to reference a Node in a context where it does not exist.
When I do something as simple as:
I've traced it to the append() method.
- append: function() {
- return this.domManip(arguments, true, function( elem ) {
- if ( this.nodeType === 1 ) {
- // this line explodes
- this.appendChild( elem );
- }
- });
- },
When I "console.dir(elem)" I get a "Object". And if I trace that back, I see domManip() cloning a "fragment", which is of type "DocumentFragment".
So I checked out domManip() who's relevant part looks like this:
- if ( first ) {
- table = table && jQuery.nodeName( first, "tr" );
- for ( var i = 0, l = this.length, lastIndex = l - 1; i < l; i++ ) {
- callback.call(
- table ?
- root(this[i], first) :
- this[i],
- results.cacheable || (l > 1 && i < lastIndex) ?
- jQuery.clone( fragment, true, true ) :
- fragment
- );
- }
- }
Now with a breakpoint in domManip() right before the callback() I tried the following:
- this[i].appendChild(jQuery.clone( fragment, true, true ))
Which crashed with the above error. Then I tried:
- this[i].appendChild(fragment.cloneNode(true))
Which worked as intended. However "table" was set to true, and my page lacks any table whatsoever, which I found odd.
My current theory is that under some sort of circumstance I can't figure out $.clone() is not cloning an object properly, and causing the browser to raise an exception because jQuery tries to append a non-node object to a node.
Could it be how the HTML is added to the DOM? This is part of a very AJAX heavy app/framework with JS controlling HTML being written to the DOM in a lot of different ways.
If anyone has a clue why this is exploding based on some knowledge of jQuery internal that I lack, I sure would be grateful. Because this is pretty frickin' weird.