IE & appendchild not working ...

Hi,

As expected I’m having some troubles to append an element into another in IE.
Other browsers are working.

My code:

		var divToInsert = document.createElement('div');
		divToInsert.setAttribute('id', 'layer');
    	
    	var page_content = document.getElementById("page");
    	page_content.appendChild(divToInsert);

I’m not getting an error in IE. Someone has an idea?

Thanks!

Yaeko said

Hi,

As expected I’m having some troubles to append an element into another in IE.
Other browsers are working.

My code:

		var divToInsert = document.createElement('div');
		divToInsert.setAttribute('id', 'layer');
    	
    	var page_content = document.getElementById("page");
    	page_content.appendChild(divToInsert);

I’m not getting an error in IE. Someone has an idea?

Thanks!


I did a search and found the following: http://karma.nucleuscms.org/item/101

Interesting, so basically reverse a few lines and it should work?

var divToInsert = document.createElement('div');
var page_content = document.getElementById("page");
page_content.appendChild(divToInsert);
divToInsert.setAttribute('id', 'layer');

hmm - something tells me IE won’t like adjusting the ID of an element once it’s on the page. Maybe try to use “class” instead of “id” if you have more problems.