Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,959
    Thanks
    120
    Thanked 76 Times in 76 Posts

    uncaught exception .."Node cannot be inser..

    Code:
        //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 ?

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,959
    Thanks
    120
    Thanked 76 Times in 76 Posts
    Code:
        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:
    Code:
    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 ?
    Last edited by BubikolRamios; 10-19-2008 at 12:17 PM.

  • #4
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,959
    Thanks
    120
    Thanked 76 Times in 76 Posts

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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
    Code:
            mClickDiv.setAttribute('class','mClickDiv');/// for FF
            mClickDiv.setAttribute('className','mClickDiv');//for IE 6.0
    That is better written as mClickDiv.className='mClickDiv'; which works in all browsers.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • The Following 2 Users Say Thank You to liorean For This Useful Post:

    BubikolRamios (10-19-2008), oesxyl (10-19-2008)

  • #6
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,959
    Thanks
    120
    Thanked 76 Times in 76 Posts
    Thanks a bunch, on both informations.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •