On 2008-10-12 19:03, Thomas 'PointedEars' Lahn wrote:
>>[...] In current browsers, even if your document is XHTML, you
can assign what you retrieved from one element's innerHTML
property to another element's innerHTML property without errors.
Of course you cannot. That is only possible when the XHTML markup is
not regarded XHTML but tag soup in the first place.
Did you actually test that? Then give me a counter example where you get
an error when at 'node2.innerHTML = node1.innerHTML'. And yes,
definitely is possible in valid XHTML documents.
There are a number of caveats, of course: copying content in this way
may lead to duplicate id attributes; setting innerHTML on an img element
isn't going to do anything useful; inserting the innerHTML of a tbody
into a div won't create table rows there; etc. But you get the point.
>>Older browsers like Firefox v1 or Safari v? did not support
innerHTML as a setter in XML documents, even though reading the
value would work.
It is not a matter of the browser but of the used markup parser. But
even if writing or reading the property would work there, it would
accomplish nothing useful, given that the languages in question are
largely incompatible.
I was under the impression that the same parser was used for both HTML
and XHTML, only running in different modes. And you can verify for
yourself that using innerHTML as a setter in XHTML documents does in
fact work. Whether you think that's "useful" is up to you.
I assume (without having checked the source), that the value returned by
innerHTML will never be a "tag soup", but the browser's parsed and
prepared representation of the source (X)HTML. The other way around,
when using innerHTML as a setter, the engine will do its best to convert
whatever it's given to a valid (X)HTML fragment.
>>I don't think there's any way to get the literal markup contents
of an element, at least not through the DOM. [...]
It is possible.
How?
Since the property is called `innerHTML', and not `innerXHTML', on
purpose, and the parsing of `<br/>' like `<br>' by tag-soup parsers
is merely based on false error-correction (correct would have been to
parse it the same as `<br>>') [..]
It appears that in current implementations the methods that implement
innerHTML are aware of the document language, and are transparently
converting between HTML and XHTML. At the time when Microsoft created
innerHTML, XHTML was still a few years away from being a standard, which
would explain the name and the way it behaves.
- Conrad