When creating new html node in jQuery using
$('<some-node>some html code</some-node>');
it won't become part of DOM, until you attach it. However, it does not mean, the node has no parent.
If the node was created unempty, e.g.:
var myNewNode = $('<div>Hello</div>');
You can check the parent:
myNewNode[0].parentNode; // Who is the parent?
and see you get
DocumentFragment
as result. DocumentFragment is some object similar to document, however, not part of the DOM tree.
The strange thing comes now. When you create an empty node, like
var myNewEmptyNode = $('<div></div>');
and try to check its contents
myNewEmptyNode[0].parentNode; // Who is now the parent?
surprisingly you get
null
I cannot understand this behaviour and found nothing about it in jQuery documentation. I found it when trying to debug why javascriptMVC mxui modal was failing on an empty div.
I have tested this behaviour in both Chromium and Opera, so it does not seem to be a browser related issue.
Does someone have an explanation for this?