Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #8358

Re: David Mark's Javascript Daily - Volume #3 - Tip #6 - How to Get and Set HTML

From Andreas Bergmaier <andber93@web.de>
Newsgroups comp.lang.javascript
Subject Re: David Mark's Javascript Daily - Volume #3 - Tip #6 - How to Get and Set HTML
Date 2011-11-15 22:26 +0100
Organization albasani.net
Message-ID <j9ulej$141$1@news.albasani.net> (permalink)
References <b8aaaf65-2095-4145-8992-651aae0e9a69@p9g2000vbb.googlegroups.com>

Show all headers | View raw


David Mark schrieb:
> Despite there being no standard behind the innerHTML property and the
> somewhat awkward feel of dealing with serialized DOM structures, I
> virtually always choose the string over the (XML) document object.
> It's much simpler, faster, requires less code, less function calls
> and, having debuted in IE 4, has enough successful history behind it
> to be trusted.

Why is that faster? Only because the native html parser is faster than 
the javascript interpreter?
I could understand the use of innerHTML when it's for large static 
elements delivered as plain text per ajax - where the server can 
serialize the structure into HTML. But when it comes to elements with 
event listeners, I absolutely prefer DOM building methods.
Using a "library" function that takes the element name, attributes, 
child nodes and event listeners as attributes, I can build dom 
structures much easier than (hand)writing serialized html strings.
Also I can't believe that it would be faster to serialize the structure 
to a string, process this with the innerHTML parser, and then dig in the 
dom tree again to set the listeners (Thats what I really hate jQuery for).
Using plain dom methods (document.createElement, 
document.createTextNode, el.appendChild, el.addEventListener) I've never 
experienced problems with tables or select elements, and I'm not limited 
to divs.
Or does that only work in recent browsers?

  Bergi

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

David Mark's Javascript Daily - Volume #3 - Tip #6 - How to Get and Set HTML David Mark <dmark.cinsoft@gmail.com> - 2011-11-15 11:47 -0800
  Re: David Mark's Javascript Daily - Volume #3 - Tip #6 - How to Get and Set HTML Andreas Bergmaier <andber93@web.de> - 2011-11-15 22:26 +0100
    Re: David Mark's Javascript Daily - Volume #3 - Tip #6 - How to Get and Set HTML Gregor Kofler <usenet@gregorkofler.com> - 2011-11-15 22:57 +0100
    Re: David Mark's Javascript Daily - Volume #3 - Tip #6 - How to Get and Set HTML "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-15 21:16 -0200
    Re: David Mark's Javascript Daily - Volume #3 - Tip #6 - How to Get and Set HTML Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-16 01:11 +0100
      Re: David Mark's Javascript Daily - Volume #3 - Tip #6 - How to Get and Set HTML Andreas Bergmaier <andber93@web.de> - 2011-11-16 02:29 +0100
  Re: David Mark's Javascript Daily - Volume #3 - Tip #6 - How to Get and Set HTML Dr J R Stockton <reply1146@merlyn.demon.co.uk> - 2011-11-16 18:51 +0000

csiph-web