Code:
<!DOCTYPE html>
<html>
<head>
<title>Add / Remove Element</title>
<script type="text/javascript">
this_num = 1;
function addElement(){
var $top = document.getElementById('top');
var newId = document.createElement('div');
var id = 'my'+this_num;
newId.setAttribute('id', id );
var str = "<a href='' onclick='removeThis(this);return false'>";
str += "Remove this element: "+id+"</a>";
newId.innerHTML = str;
$top.appendChild(newId);
this_num++;
}
function removeThis(obj){
//var d = document.getElementById('top');
//d.removeChild(id);
var el = obj.parentNode;
el.parentNode.removeChild(el);
}
</script>
</head>
<body>
<input type="button" name="button" value="Add Element" onclick="addElement()" />
<div id="top"></div>
</body>
</html>
Last edited by Padonak; 05-08-2012 at 04:30 PM.
use [code]YOUR CODE GOES HERE[/code] or burn in Hell
Bookmarks