Jump to content

[SOLVED] Cannot delete child using removeChild()


MrMastermind

Recommended Posts

Hi,

 

I'm trying to write a function that gets the innerHTML from hidden DIV's to generate a javascript file. After the innerHTML is written to another DIV, I want to delete the div. But somehow I can't get it right. The best I could do was "d.parentNode.removeChild(child);" but that doesn't work. I've tried other approaches, but no luck. Any help would be appreciated:

 

function createJS(){
	var d = document.getElementById('eFormOutput');

	var children = d.childNodes;
	var code = "";
	for(i=0;i<children.length;i++){
			var child = children[i].childNodes[0];
			if(child.id.substring(0,2) == "js"){
				code += "\n" + child.innerHTML;
				d.parentNode.removeChild(child);
			}
	}
	document.getElementById("jsOutput").innerHTML += code;
}

 

 

Thanks in advance!

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.