JavaScript IE appendChild() - Unexpected call to method or property access

后端 未结 7 808
旧巷少年郎
旧巷少年郎 2021-01-13 08:55

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

7条回答
  •  被撕碎了的回忆
    2021-01-13 09:15

    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:

    
    

    or dynamically via javascript (Probably should be wrapped in try/catch):

    var namespaces = document.namespaces;
    if(namespaces) {
        namespaces.add("foo", null, null);
    }
    

提交回复
热议问题