innerHTML ?

Hello,

I’m currently about to write a small JavaScript app that prints some text into an empty (already existing) div box.

The JavaScript file will be implemented as an external file called before the tag (to ensure that I can access the div box).

But the text to insert contains some HTML elements that must get properly handled.

When using the official way (at least the one I can imagine), e.g.
document.getElementById(“NewsHeadline”).childNodes[0].nodeValue=“Here is some important content to read.”

the HTML elements are printed “as is” and not processed.

However trying the dirty trick with innerHTML, e.g.
document.getElementById(“NewsHeadline”).innerHTML=“Here is some important content to read.”

anything is fine and “bold” text appears bold.

But I’m aware that innerHTML is not officially supported by the language standards.

Is innerHTML widely accepted across all browsers (JavaScript engines) or is there a more elegant solution on how to handle this ?

Any hint is appreciated :slight_smile:

Bye,
Tobias.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

It is so widely used as to be a new standard. IE5+, all modern (i.e.
Mac OS X) Mac browsers, Firefox of all nations, etc. I don’t know much
about Opera, but then you may not see too many of those at your
application either!

Walter

On Dec 22, 2010, at 1:14 PM, tobiaseichner wrote:

Is innerHTML widely accepted across all browsers (JavaScript
engines) or is there a more elegant solution on how to handle this ?


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

@waltd: Thank you for your reply :slight_smile:

I’ll give it a try with Opera (also have some older versions of Firefox and IE here), but good to know that others are also using innerHTML.

Tobias.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options