In the w3school site there are two tutorials:
I want to know the releationship of them, since I think the HTML DOM is one kind of XML DOM.
So the methods/properties in the XML DOM can be used in HTML DOM, and the HTML DOM may own some special methods.
However, when I try to use this:
HTML:
<span id="con">xxx</span>
var a=document.createElement("a");
document.getElementById("con").appendChild(a);
It does not work in IE.
So I wonder what is the problem?
DOM refers to a tree you make out of XML. The tree is made up of nodes. For example:
turns into a tree with three nodes: one for
aand one forband one for the text. The nodes contains the attributes as fields. So theanode will have a field:x="bb".HTML is (practically) XML so you can build a DOM tree out of it. HTML is just XML with predefined elements. I.e., you can’t use whatever names you want for your elements (you can’t use
<children>,<ball>,…) you can use the predefined names (a,span,div, …).I say “practically” because HTML is usually broken XML (for example using
<br>is wrong XML. you should use<br />instead). The browsers have smart parsers that know how to overcome this broken XML and make a usuable tree out of the HTML.