In:
Code:
var div = document.getElementById(divId), child;
child is undefined. It's given a value in the highlighted section during each iteration of the while loop:
Code:
while(child = div.firstChild){
div.removeChild(child);
}
Each time the code loops through that, the first child (a label element in this case, in some browsers there will also be empty text nodes to remove) in the division is removed until there are no children left.
But you asked a good question because some browsers might keep the checkbox's onclick event around in its garbage heap sapping memory. So that entire function should be:
Code:
function deleteAll(divId){
var div = document.getElementById(divId), child, box;
while(child = div.firstChild){
if(child.getElementsByTagName && (box = child.getElementsByTagName('input')[0])){
box.onclick = null;
child.removeChild(box);
}
div.removeChild(child);
}
}
to get rid of the checkbox and its onclick event first before removing the label element.
In:
Code:
label.removeChild(this);
this refers to the checkbox that was clicked. I don't see any textbox, perhaps you are referring to the label element. That's identified here:
Code:
var label = this.parentNode;
and removed here:
Code:
label.parentNode.removeChild(label);
Another thing occurred to me while looking this over again. In the creation part, I think the intent is to make the label be for the checkbox so that clicking on it will be the same as clicking on the checkbox. If so, change the creation function to:
Code:
function createchkboxes()
{
for (var i = 0; i < 10; i++) {
var label = document.createElement('label');
var br = document.createElement('br');
//var alabel = document.getElementById("<%=Label3.ClientID %>");
var alabel = document.getElementById('div1');
var last = alabel[alabel.length - 1];
label.appendChild(Createcheckbox(label.htmlFor = 'test' + i));
label.appendChild(document.createTextNode('kings' + i));
label.appendChild(br);
//document.getElementById("<%=Label3.ClientID %>").appendChild(label);
document.getElementById('div1').appendChild(label);
}
}
Bookmarks