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


Groups > comp.lang.javascript > #33688

Re: Cloning a table and not allowing click anywhere to trigger this event

Newsgroups comp.lang.javascript
Date 2017-08-04 14:00 -0700
References (1 earlier) <6a61845c-26e6-44d3-8e2c-ca8e4a35b833@googlegroups.com> <ce7d333c-2102-4456-833c-3341032c75f9@googlegroups.com> <XnsA7C6749794CBFeejj99@194.109.6.166> <584002a8-2bd3-4737-9a7f-b7328111cb48@googlegroups.com> <a08b17f4-4277-4fab-937b-37402e297faa@googlegroups.com>
Message-ID <d7b7e3f2-b67d-4036-bf5d-d3c19479ba47@googlegroups.com> (permalink)
Subject Re: Cloning a table and not allowing click anywhere to trigger this event
From justaguy <lichunshen84@gmail.com>

Show all headers | View raw


On Friday, August 4, 2017 at 3:50:30 PM UTC-4, justaguy wrote:
> On Thursday, August 3, 2017 at 2:34:50 PM UTC-4, justaguy wrote:
> > On Thursday, August 3, 2017 at 5:27:49 AM UTC-4, Evertjan. wrote:
> > > justaguy  wrote on 03 Aug 2017 in
> > > comp.lang.javascript: 
> > > 
> > > >> > </table>
> > > >> 
> > > >> Never mind, solved.  append any new child to a fake div below it,
> > > >> that's it.
> > > 
> > > "Fake" is so very Trumpian!
> > > 
> > > What about:
> > > 
> > > <script type='text/javascript'> 
> > > 'use strict';
> > > function duplicateAfter(t) {
> > >   t.insertAdjacentElement('afterend',t.cloneNode(true));
> > > };
> > > </script>
> > > 
> > > <table onclick='duplicateAfter(this);'>
> > > <tr><td>Blah
> > > </table>
> > > 
> > > Warning: any id will be illegally duplicated too!
> > > 
> > > > But it would be good to know if we have a way to copy elements structure
> > > > only instead of default elements and their respective values.
> > > 
> > > Elements have content, do you mean that? 
> > > 
> > > You would have to insert the new content anyway,
> > > so replacing content would do fine.
> > > 
> 
> I still wonder if we have a simple way to copy elements without their respective values. For instance, after a user fills the two INPUT fields in the sample table and then click on the clone function, then, I'd like the same two fields to show up without values (from the copied node), that is, just empty INPUT fields.
> 
> What's the correct syntax for something like the following without looping through an entire node?
> 
> function duplicateAfter(t) { 
>   /* something like the following? */
>   newNode = t.cloneNode(true);
>   if (newNode('tagName') == 'input') {
>     // set the element's value to nothing
>      element.value = '';
>     }
>   /* end of making field empty
>   t.insertAdjacentElement('afterend',newNode); 
> 
> 
> Thanks.

Ahe, it's getElementsByTagName, but looping through all the elements is a price.

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


Thread

Cloning a table and not allowing click anywhere to trigger this event justaguy <lichunshen84@gmail.com> - 2017-08-02 13:53 -0700
  Re: Cloning a table and not allowing click anywhere to trigger this event justaguy <lichunshen84@gmail.com> - 2017-08-02 15:45 -0700
    Re: Cloning a table and not allowing click anywhere to trigger this event justaguy <lichunshen84@gmail.com> - 2017-08-02 21:29 -0700
      Re: Cloning a table and not allowing click anywhere to trigger this event "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-08-03 11:27 +0200
        Re: Cloning a table and not allowing click anywhere to trigger this event justaguy <lichunshen84@gmail.com> - 2017-08-03 11:34 -0700
          Re: Cloning a table and not allowing click anywhere to trigger this event justaguy <lichunshen84@gmail.com> - 2017-08-04 12:50 -0700
            Re: Cloning a table and not allowing click anywhere to trigger this event justaguy <lichunshen84@gmail.com> - 2017-08-04 14:00 -0700
        Re: Cloning a table and not allowing click anywhere to trigger this event justaguy <lichunshen84@gmail.com> - 2017-08-04 19:06 -0700
          Re: Cloning a table and not allowing click anywhere to trigger this event "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-08-05 10:38 +0200
  Re: Cloning a table and not allowing click anywhere to trigger this event JR <jrfaqcom@gmail.com> - 2017-08-05 13:07 -0300

csiph-web