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


Groups > comp.lang.javascript > #26564

Re: Dynamically add/remove code in browsers

From Joao Rodrigues <groups_jr-1@yahoo.com>
Newsgroups comp.lang.javascript
Subject Re: Dynamically add/remove code in browsers
Date 2015-01-12 22:06 -0200
Organization Aioe.org NNTP Server
Message-ID <m91nhq$lrd$1@speranza.aioe.org> (permalink)
References <m905b3$90j$1@dont-email.me> <11460823.sCPipJV62P@PointedEars.de> <m914le$e0f$1@speranza.aioe.org> <28422568.EsDYu13dd2@PointedEars.de>

Show all headers | View raw


On 01/12/2015 07:01 PM, Thomas 'PointedEars' Lahn wrote:
> Joao Rodrigues wrote:
> 
>> On 12/01/2015 14:21, Thomas 'PointedEars' Lahn wrote:
>>> If you are accessing the “script” element by object reference, so it does
>>> not need an ID.
>>
>> However, what if there are other scripts in the document?
> 
> Then a dynamically inserted “script” element with an ID would be an 
> additional problem because IDs must be unique.

Oops. In fact, I was pondering your suggestion about using
document.getElementsByTagName("head")[0], instead of
document.getElementsByTagName("script")[0].


>> And what if the new script element already exists? Then, an ID would be of
>> great value to optimization.
> 
> On the contrary.  You would need to determine if the ID was already used by 
> an element 

Exactly!

> and try a different one until you find an unused one.  And for 
> what?  If you have a reference to the object that represents the “script” 
> element that you inserted before, you can simply reuse that reference (if 
> you think you need to remove it).  No ID necessary, and no 
> document.getElementById() calls necessary.

The intention was to avoid duplicate scripts, not to reuse the same script:

  if (document.getElementById(id)) { return; }


-- 
Joao Rodrigues

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


Thread

Dynamically add/remove code in browsers "Leonardo Azpurua" <leonardo@exmvps.org> - 2015-01-12 05:22 -0430
  Re: Dynamically add/remove code in browsers Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-12 17:21 +0100
    Re: Dynamically add/remove code in browsers Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-01-12 16:44 -0200
      Re: Dynamically add/remove code in browsers Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-12 22:01 +0100
        Re: Dynamically add/remove code in browsers Joao Rodrigues <groups_jr-1@yahoo.com> - 2015-01-12 22:06 -0200
          Re: Dynamically add/remove code in browsers Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-13 01:11 +0100
    Re: Dynamically add/remove code in browsers "Leonardo Azpurua" <leonardo@exmvps.org> - 2015-01-12 15:21 -0430
      Re: Dynamically add/remove code in browsers Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-12 22:03 +0100
    Re: Dynamically add/remove code in browsers Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-01-13 12:17 -0200
      Re: Dynamically add/remove code in browsers Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-13 20:50 +0100

csiph-web