0

The following code works fine in chrome and Firefox, but breaks in IE 9.0.

message.nodeTree.childNodes[1].childNodes[0].childNodes[0].appendChild(pkf_util.createXmlTextNode(text));

when I try to input something via textarea,it comes with SCRIPT5022:

DOM Exception: HIERARCHY_REQUEST_ERR (3) line 481 character 29;

Any ideas why it's not working in IE 9.0?

Josh Unger
  • 6,717
  • 6
  • 33
  • 55
PeterLin
  • 31
  • 1
  • 1
  • 8
  • 2
    There's no telling without seeing your HTML structure, but the code _does_ look very fragile. – John Dvorak Nov 12 '12 at 12:41
  • Since you've tagged jQuery, you should use it as well, and not navigate "second child's first child's first child" style but rather "an input with class `.data` within the div that was clicked" style – John Dvorak Nov 12 '12 at 12:43
  • What is suppose to return function createXmlTextNode() ? – A. Wolff Nov 12 '12 at 12:46
  • "Dom exception 3" means you're trying to append something where it doesn't belong, such as appending something that isn't an HTML node to an HTML document. – John Dvorak Nov 12 '12 at 12:48
  • see also this one: http://stackoverflow.com/questions/1256394/what-exactly-can-cause-an-hierarchy-request-err-dom-exception-3-error – Georgii Ivankin Feb 01 '13 at 12:18

3 Answers3

9

I know its a long time since the Q was asked but I reached it based on the error message. specifically in my case I was getting the following error: "HIERARCHY_REQUEST_ERR: DOM Exception 3: A Node was inserted somewhere it doesn't belong.".

I was trying to append a node that I was creating using jquery to some other node in my html document. It turned out that by mistake I used $('div') instead of $('<div>') for the creating the new (appended) node.

I hope this will help someone in the future.

epeleg
  • 10,347
  • 17
  • 101
  • 151
0

DOM exception 3 means you've tried to insert an element to a place in the DOM where it doesn't belong. (ref.)

Possible causes:

  • IE9 doesn't consider the XML node created by the library a valid DOM node.
  • The node created is a valid DOM node but it's being appended somewhere it doesn't belong (such as anything being appended to a node that's supposed to be a leaf)
  • The node created is not actually a new element, but rather a parent of the node being appended to. This would classify as a bug in the library.
  • If you try to append a null anywhere, you're practically asking for a DOM exception. Perhaps your library fails on IE9?

Google search on pkf_util returns ... this question, so we cannot rule out a bug in pkf_util.

John Dvorak
  • 26,799
  • 13
  • 69
  • 83
0

This can be a solution...

var element = document.createElement('iframe');
element.src = url;
document.getElementsByTagName('body')[0].appendChild(element);    

Good luck

undess
  • 1