Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

liktid
liktid
6,387 Points

Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'

Hi there,

i am trying to recreate a some practices from one of the courses. Its about to remove a li-item from an UL and append it to another UL.

When i write my code in the following way all works finde

var removeMeandAppendMe = function() {
    var parentLi = this.parentNode;
    var goneElement = incompleList.removeChild(parentLi);
    compleList.appendChild(goneElement);

};

var li = incompleList.getElementsByTagName('li');

for (var i = 0; i < incompleList.children.length; i++) {
    var link = li[i];
    var liCheckArray = link.getElementsByTagName('input');
    var liCheck = liCheckArray[0];
    liCheck.onchange = removeMeandAppendMe;
}

When i change my code to the following i get the error "Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'".

function removeMeandAppendMe(fromList, toList) {
    var parentLi = this.parentNode;
    var goneElement = fromList.removeChild(parentLi);
    toList.appendChild(goneElement);
}

var li = incompleList.getElementsByTagName('li');

for (var i = 0; i < incompleList.children.length; i++) {
    var link = li[i];
    var liCheckArray = link.getElementsByTagName('input');
    var liCheck = liCheckArray[0];
    liCheck.onchange = removeMeandAppendMe(incompleList, compleList);
}

Can anyone tell my why and where my mistake is? Thank you.

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Take a look at this discussion on this topic. Seems to offer some good insight on what happens when you do a removeChild.

Hope it helps,

Ken

liktid
liktid
6,387 Points

Thanx for the link but i already did know this discussion and honestly i didnt get it. What bothers me the most, is the fact that the code runs well when my removeMeandAppendMe-function is without parameters and doesnt work with parameters.