wellso
asked on
Adding & Removing Nodes in JavaScript
HI there,
I am using this code to generate <a> nodes that remove themselves when clicked. However I can't seemt o get the removeNode fucntion to work, Firebug shows the error I am reciving as
uncaught exception: Node was not found (NS_ERROR_DOM_NOT_FOUND_ER R)
[Break on this error] docBody.removeChild(node);
Can anyone point me in the right direction?
I am using this code to generate <a> nodes that remove themselves when clicked. However I can't seemt o get the removeNode fucntion to work, Firebug shows the error I am reciving as
uncaught exception: Node was not found (NS_ERROR_DOM_NOT_FOUND_ER
[Break on this error] docBody.removeChild(node);
Can anyone point me in the right direction?
function addNode(id) {
var inText = document.getElementById(id).innerHTML;
var newText = document.createTextNode(inText);
var newContact = document.createElement("a");
newContact.setAttribute('id',id);
newContact.appendChild(newText);
newContact.setAttribute('href','#');
newContact.setAttribute('onclick','removeNode('+id+')');
+
var docBody = document.getElementById("contactlist");
docBody.appendChild(newContact);
document.getElementById('livesearch').style.display = 'none';
document.getElementById('txt1').value = '';
return false;
}
function removeNode(id)
{
var docBody = document.getElementById("contactlist");
var node = document.getElementById(id);
docBody.removeChild(node);
}
ASKER
FIrebug is returning
document.getElementById(id ).removeNo de is not a function
maybe because of a name conflict with what i have called the fucntion?
document.getElementById(id
maybe because of a name conflict with what i have called the fucntion?
It wouldn't be a function if the result of document.getElementById(id ) is null (i.e., element is not found).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, that worked great, think Mozilla wasnt liking the removeNode method.
Open in new window