I have been having this problem in IE. I have two divs which I use to drag selected elements from one to another. Lets say I have a child element (also a div) in div1 and so
I had this issue in IE7 and it turned out to be that the IE7 DOM was not perfect.
In my case I had an image tag rendered by the ASP.NET MCV TagBuilder, which rendered it as:
<img ...></img>
Note the ending tag there and that was what caused the problem. It worked when rendered as:
<img ... />
Hope this helps.
just had the same problem with IE7, cured it by adding a timeout:
setTimeout(function(){gallery.appendChild(g_field)},300);
I've lost count of the no of times something doesn't work in IE but works perfectly in Firefox that can be solved by a short delay...no idea why!
Sorry! spoke to soon...turns out my timeout (in this case) didn't work.
SOLVED!... sort of I had hidden inputs within the child divs which stored the id of the item being moved for form submission. I removed the hidden inputs and placed them underneath my selectionboxes. Each time an div is moved it updates the name of the hidden to the parent divs id. It seems IE has a problem with appendChild() when the node has children. This did sometimes work and sometimes it failed. Appending a single element with no children always works. I am not sure exactly what the problem was, but the above sorted it out.
Cheers
Grep
For search results benefits - I had this same error in IE 6 and 7 "Unexpected call to method or property access" when appending a child node to a namespaced element, but the namespace hadn't been declared.
var a=document.createElement("foo:blah");
var b=document.createElement("div");
a.appendChild(b); //Fails
To get around this, I had to add the namespace declaration either into the HTML code:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:foo>
or dynamically via javascript (Probably should be wrapped in try/catch):
var namespaces = document.namespaces;
if(namespaces) {
namespaces.add("foo", null, null);
}
Are you sure it isn't dying on:
children[i].childNodes[0].name=toLocation;
What are you trying to accomplish with this line?
Seriously, try to comment it out. I don't even think it is what you think it is - isn't the right property called nodeName?
I agree with Kaze noe Koe, dynamically setting the name of elements is not the most bullet-proof practice. Unfortunately, I cannot tell you how to get rid of the error. However, I highly recommend using a JavaScript library (jQuery, Prototype, Dojo, ...). They are quite small, relatively easy to learn, and much more convenient to use than the horrible DOM API. Last but not least, they shield you from many such awkward Browser incompatibilities. Give it a try, after a couple of days you cannot imagine going back, I promise.