i have to add multiple thumbnail images(501.jpg,502.jpg etc. added in the gengrid function) in a page each of which opens another image(port.jpg) on click and on clicking another thumbnail image the port.jpg has to be removed. The problem is that the removeChild is not working in this case. Can anyone please help... here is the code
<script type="text/javascript">
var lastper=null;
function gengrid()
{
var i=0;
var num_stud=8;
var newdiv;
var divIdName;
var maindiv;
for(i=1;i<=num_stud;i++)
{
newdiv = document.createElement('div');
divIdName = '50'+i;
newdiv.setAttribute('id',divIdName);
newdiv.setAttribute('onclick','addit('+i+')');
newdiv.innerHTML = '<img src=50'+i+'.jpg alt="a"></img>';
maindiv=document.getElementById('main');
maindiv.appendChild(newdiv);
}
}
gengrid();
function addit(picno)
{
var person = document.getElementById('50'+picno);
if(lastper)
lastper.removeChild('portfolio');
var newdiv = document.createElement('div');
var divIdName = 'portfolio';
newdiv.setAttribute('id',divIdName);
newdiv.innerHTML ='<img src="port.jpg" alt="a"></img>';
person.appendChild(newdiv);
alert(picno+''+lastper.id+person.id);
lastper = document.getElementById('50'+picno);
}
</script>