...

View Full Version : uncaught exception .."Node cannot be inser..



BubikolRamios
10-19-2008, 10:28 AM
//have array with div elements
// take out last.
lastElement = myArray.splice(myArray.length-1,1)

// insert them all, except last one into outer div
for (var i = 0; i < myArray.length; i++)
{
outerDiv.appendChild(myArray[i]);
}
// add allso last one
outerDiv.appendChild(lastElement);
-->

Error: uncaught exception: [Exception... "Node cannot be inserted at the specified point in the hierarchy" code: "3" nsresult: "0x80530003 (NS_ERROR_DOM_HIERARCHY_REQUEST_ERR)"

What is this ?

liorean
10-19-2008, 11:54 AM
It's an error that occurs when you're trying to insert an object type that is not allowed as a node in that position. An example of things that can cause this error is trying to insert a JavaScript object into the DOM, trying to insert a Document into an Element, trying to insert a Notation, Entity, Doctype or Attribute node into an Element etc.

Giving us a glimpse of what the contents of myArray are or how you generated them may be helpful.

BubikolRamios
10-19-2008, 11:57 AM
for (var y = 0; y < dimY ; y++)
{
for (var x = 0; x < dimX; x++)
{
counter += 1;

var mClickDiv = d.createElement("div");
mClickDiv.style.left = ((x * squareSize)+ x +1) + 'px';
mClickDiv.style.top = ((y * squareSize) + y + 1) + 'px';
mClickDiv.style.width = squareSize + 'px';
mClickDiv.style.height = squareSize + 'px';


mClickDiv.setAttribute('class','mClickDiv');/// for FF
mClickDiv.setAttribute('className','mClickDiv');//for IE 6.0

mClickDiv.innerHTML = counter;
mClickDiv.onclick = function (){move(this)}
myArray.push(mClickDiv);
}
}


// and then
//have array with div elements
// take out last.
lastElement = myArray.splice(myArray.length-1,1)

// insert them all, except last one into outer div
for (var i = 0; i < myArray.length; i++)
{
outerDiv.appendChild(myArray[i]);
}
// add allso last one
outerDiv.appendChild(lastElement);



The error above is from FF, IE says : no such interface supported, at the same line.

And if I appendChild directly from myArray, I mean if I take out:


lastElement = myArray.splice(myArray.length-1,1)
// and ...
outerDiv.appendChild(lastElement);

then it works, last element added with no prob.

Looks like some information is lost with "lastElement = myArray.splice(myArray.length-1,1) "
allthough alert(lastElement = myArray.splice(myArray.length-1,1)) says HTMLDivElement.

Mybe things in array are only reference to elements in document, and in lastElement the element actualy becomes element, or something ?

BubikolRamios
10-19-2008, 12:35 PM
cleared example:

http://agrozoo.net/AgroZoo10/jsp/test.jsp

liorean
10-19-2008, 12:37 PM
myArray.splice returns an array containing the removed elements from the array. You need to extract the Element from that array.

Also, I see you're using
mClickDiv.setAttribute('class','mClickDiv');/// for FF
mClickDiv.setAttribute('className','mClickDiv');//for IE 6.0That is better written as mClickDiv.className='mClickDiv'; which works in all browsers.

BubikolRamios
10-19-2008, 12:49 PM
Thanks a bunch, on both informations.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum