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


Groups > comp.lang.javascript > #39671 > unrolled thread

Using HTML5 templates

Started byAndrew Poulos <ap_prog@hotmail.com>
First post2021-03-17 15:40 +1100
Last post2021-03-18 07:47 +1100
Articles 3 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  Using HTML5 templates Andrew Poulos <ap_prog@hotmail.com> - 2021-03-17 15:40 +1100
    Re: Using HTML5 templates "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-03-17 06:08 -0700
      Re: Using HTML5 templates Andrew Poulos <ap_prog@hotmail.com> - 2021-03-18 07:47 +1100

#39671 — Using HTML5 templates

FromAndrew Poulos <ap_prog@hotmail.com>
Date2021-03-17 15:40 +1100
SubjectUsing HTML5 templates
Message-ID<HISdnR0V-cLSFcz9nZ2dnUU7-bfNnZ2d@westnet.com.au>
If I have a simple template that looks like this

<template id="my-paragraph">
   <p id="foo">My paragraph</p>
</template>

When I clone the template multiple times I have multiple elements with 
the id of "foo".

So if the template I've be given to use is fairly large (with many 
elements with IDs) how would I use it? I suspect that before the clone 
is appended to the DOM I'll need to loop through all the elements and 
edit the IDs so that they are unique - which complicates referencing them.

Is this correct or am I misunderstanding how a is to be used template?

Andrew Poulos

[toc] | [next] | [standalone]


#39675

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2021-03-17 06:08 -0700
Message-ID<978657c1-32a8-414c-892a-1bbd6d988e62n@googlegroups.com>
In reply to#39671
On Tuesday, March 16, 2021 at 11:40:58 PM UTC-5, Andrew Poulos wrote:
> If I have a simple template that looks like this 
> 
> <template id="my-paragraph"> 
> <p id="foo">My paragraph</p> 
> </template> 
> 
> When I clone the template multiple times I have multiple elements with 
> the id of "foo". 
> 
> So if the template I've be given to use is fairly large (with many 
> elements with IDs) how would I use it? I suspect that before the clone 
> is appended to the DOM I'll need to loop through all the elements and 
> edit the IDs so that they are unique - which complicates referencing them. 
> 
> Is this correct or am I misunderstanding how a is to be used template? 

Correct, you'll want to remove the id's.

Can you avoid having the id's in the template in the first place? Can you not use 'class' instead?

[toc] | [prev] | [next] | [standalone]


#39684

FromAndrew Poulos <ap_prog@hotmail.com>
Date2021-03-18 07:47 +1100
Message-ID<69SdnePHA55U98_9nZ2dnUU7-eGdnZ2d@westnet.com.au>
In reply to#39675
On 18/03/2021 12:08 am, Michael Haufe (TNO) wrote:
> On Tuesday, March 16, 2021 at 11:40:58 PM UTC-5, Andrew Poulos wrote:
>> If I have a simple template that looks like this
>>
>> <template id="my-paragraph">
>> <p id="foo">My paragraph</p>
>> </template>
>>
>> When I clone the template multiple times I have multiple elements with
>> the id of "foo".
>>
>> So if the template I've be given to use is fairly large (with many
>> elements with IDs) how would I use it? I suspect that before the clone
>> is appended to the DOM I'll need to loop through all the elements and
>> edit the IDs so that they are unique - which complicates referencing them.
>>
>> Is this correct or am I misunderstanding how a is to be used template?
> 
> Correct, you'll want to remove the id's.
> 
> Can you avoid having the id's in the template in the first place? Can you not use 'class' instead?
> 
Thanks. Yes I could but it means tracking down any getElementById and 
replacing it with querySelector.

Andrew Poulos

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web