Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #10179
| Message-ID | <5848329.bgypaU67uL@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2012-01-12 18:32 +0100 |
| Subject | Re: Cannot write to the DOM |
| Newsgroups | comp.lang.javascript |
| References | <3437926.47.1326345632135.JavaMail.geo-discussion-forums@yqiq10> <4f0ee77c$0$30355$a8266bb1@newsreader.readnews.com> |
| Followup-To | comp.lang.javascript |
Followups directed to: comp.lang.javascript
Denis McMahon wrote:
> On Wed, 11 Jan 2012 21:20:32 -0800, RH wrote:
>> function create() {
>> // create the element in the DOM
>> var listItemViewer = document.getElementById("test");
>>
>> var test = document.createElement("li"); test.innerHTML = "test list
>> item";
>> listItemViewer.appendChild(test);
>> }
>
> What the others said, but in addition, maybe this is a better create():
>
> function create() {
> var listItemViewer = document.getElementById("test");
> var test = document.createElement("li");
> test.appendChild(document.createTextNode("test list item"));
> listItemViewer.appendChild(test);
> }
>
> If you're going to use dom functions to create the list element, you
> might as well (some might even suggest should) also use the dom functions
> to add its content instead of innerHTML.
It is inefficient to retrieve the element object reference on every click.
So you should cache that somehow. However, if you are using this function
then you must by definition have either an empty `li' element in the
document already (which is not modified by this code, which would be a
rather bad idea) or you must create the `ul' element dynamically, in which
case you have the element object reference already (as I showed).
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Cannot write to the DOM RH <richkhall@gmail.com> - 2012-01-11 21:20 -0800
Re: Cannot write to the DOM Tim Streater <timstreater@greenbee.net> - 2012-01-12 09:38 +0000
Re: Cannot write to the DOM R Hall <richkhall@gmail.com> - 2012-01-12 18:52 -0800
Re: Cannot write to the DOM "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-01-12 12:06 +0000
Re: Cannot write to the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-12 13:21 +0100
Re: Cannot write to the DOM John G Harris <john@nospam.demon.co.uk> - 2012-01-13 17:06 +0000
Re: Cannot write to the DOM Gene Wirchenko <genew@ocis.net> - 2012-01-13 11:38 -0800
Re: Cannot write to the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-13 22:23 +0100
Re: Cannot write to the DOM John G Harris <john@nospam.demon.co.uk> - 2012-01-14 15:49 +0000
Re: Cannot write to the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-14 17:26 +0100
Re: Cannot write to the DOM John G Harris <john@nospam.demon.co.uk> - 2012-01-15 14:19 +0000
Re: Cannot write to the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-15 19:45 +0100
Re: Cannot write to the DOM John G Harris <john@nospam.demon.co.uk> - 2012-01-16 10:40 +0000
Re: Cannot write to the DOM Denis McMahon <denismfmcmahon@gmail.com> - 2012-01-15 20:56 +0000
Re: Cannot write to the DOM Denis McMahon <denismfmcmahon@gmail.com> - 2012-01-12 14:00 +0000
Re: Cannot write to the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-12 18:32 +0100
Re: Cannot write to the DOM RobG <rgqld@iinet.net.au> - 2012-01-17 19:26 -0800
csiph-web