473,770 Members | 7,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

innerHTML support?


Hey all,

AFAIR, innerHTML started as MS proprietary, but Mozilla implemented it
as well. Does anyone know if any other browsers support it? It is not in
the W3C DOM, is it? A quick GIS seemed to answer 'no' to that, but you
guys are better at finding these things than I am. ;)

This page seems to think Opera 7, Safari, and IE Mac are cool with it
too, and it seems to be faster. It also implies that innerHTML is NOT in
the W3C DOM. Is this right?
http://www.quirksmode.org/dom/innerhtml.html

Anyone have any caveats about innerHTML? When should it be used? When
should DOM methods be used instead?
Most importantly, do the browsers implement it the same?

TIA

--
--
~kaeli~
Do not taunt Happy Fun Ball!
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #1
11 2509
kaeli <ti******@NOSPA M.comcast.net> writes:
AFAIR, innerHTML started as MS proprietary, but Mozilla implemented it
as well. Does anyone know if any other browsers support it?
Opera 7 and Safari/Konqueror that I know of.
It is not in the W3C DOM, is it?
No.
This page seems to think Opera 7, Safari, and IE Mac are cool with it
too, and it seems to be faster.
Yes, IE (any version since IE 4), Mozilla (any Gecko based browser),
KHTML-based browsers (Konqueror and Safari) and Opera 7. That's the
ones I am certain of too.

Hmm. Faster than? :)
It also implies that innerHTML is NOT in the W3C DOM. Is this right?
http://www.quirksmode.org/dom/innerhtml.html
Absolutely.
Anyone have any caveats about innerHTML?
It's not standard. It could be slower than creating the nodes directly,
but in current Javascript, the interpretive overhead of the script
itself is worse than the parsing of HTML. That can change, probably
not significantly so.

My real dislike is for passing around unparsed HTML, for much the same
reason that I dislike using "eval": It's error prone.

You can make invalid HTML (or even plain syntactically wrong "HTML")
and enter it into an otherwise validating page, and *no* amount of
validation will tell you that. At least, when using DOM methods,
you can only make properly nested elements.

The method I recommend for adding predictable document fragments to a
page faster than with DOM methods, is to put them in the page to begin
with, inside a hidden element, and either move them or clone them when
you need it.

On the other hand, DOM methods work fine in most cases, unless you
are building humongous documents dynamically (and then innerHTML can
be slow too if used improperly).
When should it be used?
When you know the target audience will only use browsers that supports
it (including future browsers :)
When should DOM methods be used instead?
I'd say all the time, but I'm a known purist :)

On the other hand, I would never do large amounts of work with the DOM
methods directly. They are simply too verbose. I usually have utility
functions that makes it easier to build larger structures
Most importantly, do the browsers implement it the same?


Almost.

Error correction is ofcourse different, but for valid, tag-complete
HTML, the results are mostly the same. There are probably a few
more exceptions, but the only one I can remember is:
In IE, on most table-related elements the innerHTML property is
read-only (not TD and TH, but pretty much the rest).

Good luck :)
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2
In article <y8**********@h otpop.com>, lr*@hotpop.com enlightened us
with...
This page seems to think Opera 7, Safari, and IE Mac are cool with it
too, and it seems to be faster.
Yes, IE (any version since IE 4), Mozilla (any Gecko based browser),
KHTML-based browsers (Konqueror and Safari) and Opera 7. That's the
ones I am certain of too.

Hmm. Faster than? :)
It also implies that innerHTML is NOT in the W3C DOM. Is this right?
http://www.quirksmode.org/dom/innerhtml.html


If you look at the page, it compared rendering times of innerHTML vs.
Dom methods. The innerHTML won for pretty much all of them.

My real dislike is for passing around unparsed HTML, for much the same
reason that I dislike using "eval": It's error prone.
I really didn't think of that. That's a great point.
I don't use it myself, but I see solutions posted here and in other
forums that use it and I am always wondering just how good those
solutions are.
When should it be used?
When you know the target audience will only use browsers that supports
it (including future browsers :)


Well, that about takes care of that, doesn't it? ;)
When should DOM methods be used instead?


I'd say all the time, but I'm a known purist :)


Yeah, me too, that's why I was wondering. Sometimes, I'm TOO much of a
code-snob, for want of a better term. I'm really good at
overcomplicatin g things sometimes. *heh*

--
--
~kaeli~
When a clock is hungry, it goes back four seconds.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #3
On Mon, 19 Jul 2004 22:16:53 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com > wrote:
You can make invalid HTML (or even plain syntactically wrong "HTML")
and enter it into an otherwise validating page, and *no* amount of
validation will tell you that. At least, when using DOM methods,
you can only make properly nested elements.


No you can't, you can easily make an invalid DOM - for example we
often got people complaining about the TBODY required when making a
table in IE - that's not because it errored when it appended a TR to a
TABLE (which isn't valid in HTML) but because it just didn't display.
That isn't possible with innerHTML - since innerHTML will use the
implied rules from the dtd to include it.

Jim.
--
comp.lang.javas cript FAQ - http://jibbering.com/faq/

Jul 23 '05 #4
ji*@jibbering.c om (Jim Ley) writes:
On Mon, 19 Jul 2004 22:16:53 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com > wrote:
At least, when using DOM methods, you can only make properly nested
elements.
No you can't, you can easily make an invalid DOM


When I said "properly nested", I only meant that you can't create
the equivalent of "<b><i>somethin g</b></i>". You can easily
create (properly) nested elements that are not valid HTML, like
the <tr> not inside a <tbody> (which have also bitten me once :).
That isn't possible with innerHTML - since innerHTML will use the
implied rules from the dtd to include it.


True. So innerHTML allows people to write HTML as they are used
to, without understanding the structure of the HTML DOM. Whether
that is good or not, I'm not sure. Obviously, people like it :)
Something that does annoy me with innerHTML is that it doesn't
allow for appending. Doing "element.innerH TML+='<some html>';"
unparse and reparses the current content of the element, removing
any non-standard properties that might have been assigned to
the DOM nodes. IE has insertAdjacentH TML which solves that
problem, but which isn't implemented in, e.g., Mozilla.

The optimal combination of DOM and innerHTML would be a function:
parseHTML(Strin g) : DocumentFragmen t
(I've said that before, and you pointed out that it exists in the
Adobe SVG DOM (and probably will be in SVG DOM 1.2) as parseXML[1],
right?)

/L
[1] I can see that it historically belongs to the "window" object,
but it would be much prettier as a method of the document object,
so it doesn't need the documnet as argument.
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #5
On Mon, 19 Jul 2004 23:41:55 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com > wrote:
When I said "properly nested", I only meant that you can't create
the equivalent of "<b><i>somethin g</b></i>".
Ah, but with innerHTML, that would get fixed up so the DOM structure
you were entering would be a valid DOM (if ridiculous)
Something that does annoy me with innerHTML is that it doesn't
allow for appending. Doing "element.innerH TML+='<some html>';"
+1
Adobe SVG DOM (and probably will be in SVG DOM 1.2) as parseXML[1],
right?)
[1] I can see that it historically belongs to the "window" object,
but it would be much prettier as a method of the document object,
so it doesn't need the documnet as argument.


Then you couldn't use it to create a new document in one go. parseXML
takes a 2nd property which is the document to parse it in the context
of, if you leave it off you get a newly created one.

so:
doc=parseXML("< svg><!-- stuff --></svg>");

is the same as what would you'd get with something like

doc=new SVGDocument();
doc.parseXML("< svg><!-- stuff --></svg>");

so you still need some non-document interface to create the new
object, so I think you might aswell have it one go.

Jim.
--
comp.lang.javas cript FAQ - http://jibbering.com/faq/

Jul 23 '05 #6
Lasse Reichstein Nielsen wrote:
kaeli writes:
AFAIR, innerHTML started as MS proprietary, but Mozilla
implemented it as well. Does anyone know if any other
browsers support it?


Opera 7 and Safari/Konqueror that I know of.

<snip>

You can definitely add IceBrowser 5 to that list.
When should it be used?


When you know the target audience will only use
browsers that supports it (including future browsers :)

<snip>

With designed clean degradation and an effective/reliable test for
(dynamic) innerHTML support surly there is no need to know that the
client browser supports it.

Richard.
Jul 23 '05 #7
ji*@jibbering.c om (Jim Ley) writes:
On Mon, 19 Jul 2004 23:41:55 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com > wrote:
When I said "properly nested", I only meant that you can't create
the equivalent of "<b><i>somethin g</b></i>".
Ah, but with innerHTML, that would get fixed up so the DOM structure
you were entering would be a valid DOM (if ridiculous)


I wish. IE 6 actually creates a royal mess, where a node can end up
being the sibling of its grandfather (example at:
<URL:http://ln.hixie.ch/?start=10379104 67&count=1>).
Then you couldn't use it to create a new document in one go. parseXML
takes a 2nd property which is the document to parse it in the context
of, if you leave it off you get a newly created one.
So parseXML can either return a DocumentFragmen t or a Document. I
would prefer consistency rather than brevity, but I can accept it as a
reason :)
so:
doc=parseXML("< svg><!-- stuff --></svg>");

is the same as what would you'd get with something like

doc=new SVGDocument();
doc.parseXML("< svg><!-- stuff --></svg>");
The last line would probably be:
doc.appendChild (doc,parseXML(" <svg><!-- stuff --></svg>"));
(which doesn't help my point :)
so you still need some non-document interface to create the new
object, so I think you might aswell have it one go.


But now you have two ways to create a new document, and one of them
only creates a new document some times.

What happens if the argument is not a valid SVG document content,
but still a valid fragment? No, I still prefer one function for
each distinct operation, and only one. It makes mistakes harder
to make.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #8
On Tue, 20 Jul 2004 02:24:58 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com > wrote:
What happens if the argument is not a valid SVG document content,
but still a valid fragment?
Not sure what you mean, they're all just XML document - there's no
restriction on XML - SVG has little notion of a valid document, since
any SVG can contain any WF XML.
No, I still prefer one function for
each distinct operation, and only one. It makes mistakes harder
to make.


Your scripts just get too big, and too slow. I want convenience
methods - you're going to write them anyway, better then be in native.

Jim.
--
comp.lang.javas cript FAQ - http://jibbering.com/faq/

Jul 23 '05 #9
ji*@jibbering.c om (Jim Ley) writes:
On Tue, 20 Jul 2004 02:24:58 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com > wrote:
What happens if the argument is not a valid SVG document content,
but still a valid fragment?
Not sure what you mean, they're all just XML document - there's no
restriction on XML - SVG has little notion of a valid document, since
any SVG can contain any WF XML.


I thought an SVG-fragment should be delimited by <svg> and </svg> tags.
So the question would be, what is:
parseXML("<g></g>")
?
It's easy to parse "<g></g>" into a DocumentFragmen t, but can it be
an SVGDocument (and will parseXML generate an SVGDocument and not
some other Document)?
Your scripts just get too big, and too slow. I want convenience
methods - you're going to write them anyway, better then be in native.


Indeed, it's all about hitting the right level of abstraction.
I prefer clear boundaries between features to overloaded convenience
operations, but I can see why convenience is convenient :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
8452
by: Phil N | last post by:
Hello again Site I'm working on: http://www3.telus.net/bikim/lightning/test/ - 'coach' & 'main' links swap innerHTML of div element - id 'textArea' works fine in NN7; IE6 reports 'Object doesn't support this property or method' code is:
14
2532
by: catorcio | last post by:
I'm trying to have some text in my page changed by clicking a button. Googleing around I've discovered that innerText doesn't work with every browser, so I've switched to innerHTML. It works fine on IE and Opera, but nothing happens on Firefox (just updated to version 1.0.4). Any suggestions? Thanks in advance! C.
3
5300
by: soup_or_power | last post by:
Hi Sorry about the heading. I have a table with td consisting of lists with <select></select>. When I do a document.getElementById("element").innerHTML I don't see the selected item. IOW, the innerHTML is not dynamic. Is there some way to get the most recent selected without traversing through the list's options. Thank you
38
3489
by: Luke Matuszewski | last post by:
Welcome I have read the in the faq from jibbering about the generic DynWrite, but i also realized that is uses only innerHTML feature of HTML objects. (1) Is there a DOM function which is very similar to innerHTML property eg. (my guess) setInnerNodeAsText or sth... ? I want to write function which will be dynamically updateing some of my select boxes. My question is: (2.1) Can i use innerHTML property of SELECT (or even incorporate
10
12684
by: Jake Barnes | last post by:
This weekend I wanted to learn AJAX, so I set up a little toy page where I could experiment. The idea of this page is that you click in one of the boxes to get some controls, at which point you can add text, images, or HTML to the box. This seems to work fine in FireFox, but not in IE. You can see the problem here: http://www.publicdomainsoftware.org/ajaxExperiment.htm In FireFox, if you click in a box and then select "Add HTML" you...
9
8671
by: Hallvard B Furuseth | last post by:
Why does the FAQ (Q 4.15) recommend innerHTML when so many here say one should use createElement(), replaceChild() etc? Also, why does the "Alternative DynWrite function" at <http://www.jibbering.com/faq/faq_notes/alt_dynwrite.html> need such a lot of tests to find out if innerHTML assignment actually works, instead of just inserting <span id="strange name"></span> and checking if the document now contains an element with that ID?
6
2996
by: sonic | last post by:
Ok, i am sure everyone is sick of hearing about this. but i've checked about 10 different posts/sites about this issue, and they all say "use DOM" but i think there is more to be said. Perhaps I am a total newbie but the answer was not immediately obvious to me here. so.. problem: declaring doctype as xhtml will prevent myDiv.innerHtml=val from working. suggested solution:
6
10769
by: David Gillen | last post by:
Hello, I'm hoping someone can shed some light on this, problem is in IE6 and 7. FF is okay. I have within my html <tbody id="dataTable" name="dataTable"></tbody> And then some javascript (using prototype to get the element)
6
4255
by: PaPa | last post by:
I'm not sure this is a javascript issue or an HTML issue. I notice that when I extract the contents of a div using the innerHTML property (?), that I wind up with a literal variable (?) which exactly matches the contents of the div with one exception. It seems that whenever the code includes a tag which uses the forward slash against the closing bracket (say the break tag ..... />) that the browser, or HTML, or javascript, or...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.