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


Groups > comp.lang.javascript > #28276

Re: Best way to show create different elements dynamically

From danca <cyberdanny@tiscalinet.it>
Newsgroups comp.lang.javascript
Subject Re: Best way to show create different elements dynamically
Date 2015-07-05 11:43 +0200
Organization A noiseless patient Spider
Message-ID <mnau4c$5dg$1@dont-email.me> (permalink)
References <%t_lx.191314$1K1.45828@fx06.am4> <Tx_lx.191315$1K1.88992@fx06.am4> <mnaomg$l33$1@dont-email.me> <359025142.IYVrofH7X8@PointedEars.de>

Show all headers | View raw


Il 07/05/2015 10:22 AM, Thomas 'PointedEars' Lahn ha scritto:
> danca wrote:
>
>> Il 07/05/2015 02:06 AM, JiiPee ha scritto:
>>>> I use javascript to first create <p>-text lines inside a div (using
>>>> innerHTML). Then after that text I would like to show a table
>>>> (<table>). What is the best way to do this? […]
>>
>> I think you should investigate document.createElement() and
>> document.appendChild() to manipulate the DOM instead of using innerHTML.
>
> I think you should do some tests before giving advice. Including benchmarks.

I don't get the "benchmarks" part. Can you elaborate? [edit: ok, I have 
read the document you refers later in the message]

>
>> Example: (create a div, then set some properties)
>>
>> var aDiv=document.createElement('div')
>> aDiv.style.position="fixed"
>
> It is customary and recommended to use whitespace to separate tokens.
> It is recommended to use a consistent quoting style.

And I don't get this, too. I'm using Thunderbird on Linux and the 
quoting is automatic and seems to me just the same it was under 
Windows... Can you be more specific?

>> You can nest other elements into the element created (but still not
>> visible nor present in your document):
>>
>> info.appendChild(lbl)
>> aDiv.appendChild(info)
>>
>> And now append the div to the document:
>>
>> document.body.appendChild(aDiv)
>
> Good advice at last.  The reason for this order is that it prevents
> reflow/repaint in case of a race condition.  But it is still not more
> compatible or efficient with *tables*:
>
> <http://www.quirksmode.org/dom/innerhtml.html>

Interesting. Anyway, I was not concerned by any means about performance. 
And that page should be updated, it is really old stuff.
BTW isn't innerHTML generally discouraged?

>
>> […]
>> Look also to firstChild(), replaceChild(), removeChild ecc.
>
> There is no “firstChild” method, and no “removeChild” *non-callable*
> property.
>

Uh, right. Typos.

Dan

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


Thread

Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 01:02 +0100
  Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 01:06 +0100
    Re: Best way to show create different elements dynamically Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-05 09:27 +0200
      Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 10:04 +0100
    Re: Best way to show create different elements dynamically danca <cyberdanny@tiscalinet.it> - 2015-07-05 10:10 +0200
      Re: Best way to show create different elements dynamically Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-05 10:22 +0200
        Re: Best way to show create different elements dynamically danca <cyberdanny@tiscalinet.it> - 2015-07-05 11:43 +0200
          Re: Best way to show create different elements dynamically Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-05 13:16 +0200
            Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 12:48 +0100
            Re: Best way to show create different elements dynamically danca <cyberdanny@tiscalinet.it> - 2015-07-05 14:47 +0200
              Re: Best way to show create different elements dynamically Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-05 16:03 +0200
                Re: Best way to show create different elements dynamically danca <cyberdanny@tiscalinet.it> - 2015-07-05 19:53 +0200
                Re: Best way to show create different elements dynamically Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-06 01:46 +0200
                Re: Best way to show create different elements dynamically "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-06 07:29 +0200
        Re: Best way to show create different elements dynamically Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2015-07-05 13:17 +0200
    Re: Best way to show create different elements dynamically "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-07-05 10:38 +0200
      Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 10:01 +0100
      Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 10:11 +0100
        Re: Best way to show create different elements dynamically Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-05 11:17 +0200
        Re: Best way to show create different elements dynamically "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-07-05 11:26 +0200
          Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 10:30 +0100
          Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 10:33 +0100
            Re: Best way to show create different elements dynamically "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-07-05 12:29 +0200
              Re: Best way to show create different elements dynamically danca <cyberdanny@tiscalinet.it> - 2015-07-05 12:38 +0200
                Re: Best way to show create different elements dynamically "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-07-05 17:33 +0200
                Re: Best way to show create different elements dynamically danca <cyberdanny@tiscalinet.it> - 2015-07-05 18:55 +0200
                Re: Best way to show create different elements dynamically "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-07-05 19:44 +0200
                Re: Best way to show create different elements dynamically danca <cyberdanny@tiscalinet.it> - 2015-07-05 20:42 +0200
                Re: Best way to show create different elements dynamically "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-07-05 21:01 +0200
              Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 13:00 +0100
                Re: Best way to show create different elements dynamically Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-05 16:13 +0200
                Re: Best way to show create different elements dynamically Tim Streater <timstreater@greenbee.net> - 2015-07-05 15:23 +0100
                Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 15:57 +0100
  Re: Best way to show create different elements dynamically JiiPee <no@notvalid.com> - 2015-07-05 10:03 +0100

csiph-web