Remove Multiple Children From Parent?
I have a bunch on elements with the same name that i am trying to remove at the same time with an onchange function. Here is the javascript:
Solution 1:
<scripttype="text/javascript">functionremoveoldAccounts() {
var accounts = document.getElementsByName("extraaccounts");
var account;
var parent;
for (account in accounts) {
parent = account.parentNode;
parent.removeChild(account);
}
}
</script>
and...
<select id="piname" name="pi_name" onChange="removeoldAccounts();" />
Solution 2:
Something like this:
if ( e.hasChildNodes() )
{
for(var i=0; i < e.childNodes.length; i++)
{
if(e.childNodes[i].nodeName == "extraaccounts") {
e.removeChild(e.childNodes[i]);
}
}
}
Post a Comment for "Remove Multiple Children From Parent?"