Hallvard said:
Randy said:
Hallvard B Furuseth said the following on 2/26/2006 11:25 AM:
[...]
tempVar = element.innerHTML;
If the browser doesn't support innerHTML, you will get an error on
that line. Attempting to set it first and then read it won't cause an
error (if the browser supports setting properties that way).
There will only be an error if `element' is a null object reference,
throwing a ReferenceError exception then. So far all known DOM
implementations work according to the [[Get]] property access method
of the ECMAScript specification (although they do not have to).
Therefore, if `innerHTML' is not supported, the reference evaluates
to `undefined', and nothing breaks.
Unconditional _write_ ([[Put]] property) access to the `innerHTML'
property is a different thing, though.
Hm? Firefox, IE and Opera do not fail on 'tempVar = element.urgle;'.
As expected. (However, Firefox's error console would yield a warning here.)
Will some browsers do so?
I know of none.
I hope none fail on 'if (document.all)'...
That depends on how you define `fail'. This breaks in no known user agent
breaks, but not all user agents evaluate `document.all' to `true' here.
The "Alternative DynWrite()" page does mention a browser which will err
on attempts to test/read/modify HEAD elements. But it wraps those tests
in "if (typeof element.innerHTML == 'string')", maybe that avoids the
problem.
If there is a problem, yes. A `typeof' operation only evaluates the type
of its argument, not its value. So there is no [[Get]] property access
then.
Anyway, in my case I'll just avoid .innerHTML for HEAD elements.
Good man.
and of input elements.
Pardon?
And, and, and...
There are good reasons to use `innerHTML' _occasionally_, though. Splitting
text nodes to insert an element for a word, for example, can be a real PITA
with standards compliant DOM access. I posted an example the other day.
Yuck. Looks like one should be even more careful about innerHTML than I
had yet realized.
Yet I wonder if such a user agent even exists or could exist successfully
in the future. I know of none.
[...]
The reason I can think of is still that some browser might do the
opposite - recognize the dynamically inserted IDs, but not insert the
HTML.
Improbable. Markup has to be parsed into a tree before the respective
element nodes and text nodes can be inserted. (Which is the main
drawback of using innerHTML & Co. compared to W3C DOM methods.)
Or it could simply be that with innerHTML it's best to be as
paranoid as at all possible.
Seldom good things come from paranoia, if that.
BTW, any special reason to use <strong>?
To mark up said:
I'd think something less visible would be better for the test,
like <span> or <tt>.
<span style="font-weight:bold">foo</span> cannot tell a screen reader that
"foo" is very important and therefore has to be strongly emphasized. And
`strong' elements are usually rendered bold (as being strongly emphasized
compared to the rest of the text), so you can address both visual and aural
user agents with only one element. (I would define a rule with emphasizing
aural CSS properties for `strong', however a screen reader is likely to
have it in its basic stylesheet already.)
The `tt' (teletype) element is for text content that should be marked up
as being typed by the user, such as commands in a manual or tutorial.
Therefore it is often rendered as teletype or monospaced text. See the
specs.
HTH
PointedEars