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); } What bothers me, is the fact that the code runs well when my removeMeandAppendMe-function is without parameters and doesnt work with parameters. Can anyone tell my why and where my mistake is? Thank you.
(I'm aware of the blur-problem discussed here: Failed to execute 'removeChild' on 'Node')
incompleteList? Where is it assigned?incompleteListandcompleListare the ids of the both unordered listsremoveMeandAppendMe, you are invoking it. I would suggest looking into the.bind()function to achieve what you're looking to do.