Quote:
Originally Posted by docco
I can not understand what's wrong with the below. Can not remove child in Crome. Anyone help
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Add & Delete Child</title>
</head>
<body>
<script type=text/javascript>
var childID=0;
function addChild()
{
var parent = document.getElementById('myDiv');
var newChild = document.createElement('div');
childID=childID+1;
var childName = 'Div'+childID; // set index for child for deleting later
newChild.setAttribute('id',childName);
newChild.innerHTML = 'Element '+childName+' has been added! <a href=\'#\' onclick=\'removeElement('+childName+')\'>Remove element "'+childName+'"</a>';
parent.appendChild(newChild);
}
function removeElement(divName)
{
var parent = document.getElementById('myDiv');
var oldDiv = document.getElementById(divName);
parent.removeChild(oldDiv);
}
</script>
<p><button onclick="addChild();">Add New Elements</button></p>
<div id="myDiv"> </div>
</body>
</html>
|
I suggestion putting your script in the <head>, not the <body>. Beyond that, sorry, I'm not sure.
Raymond