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


Groups > comp.lang.javascript > #22666

Re: Duplicating the last row of a Table

Newsgroups comp.lang.javascript
Subject Re: Duplicating the last row of a Table
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <ZemAs3VzQa2SFwhs@invalid.uk.co.demon.merlyn.invalid>
Date 2014-01-18 12:16 +0100
Message-ID <XnsA2B97CDBE63E3eejj99@194.109.133.133> (permalink)

Show all headers | View raw


Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> wrote on 17 jan 2014 
in comp.lang.javascript:

> I wish to duplicate the last row of a Table, which contains cells like
> <td>text</td> and <td><input type=text ...></td>, with a view to then
> replacing the input elements with test representing their values (which
> seems easy).
> 
> 
> In HTML, I have something like
> 
>         <table>         <!-- abbreviated -->
>         <tbody ID=TB>
>         <tr><td><input type=text ...></td><td>AA</td></tr>
>         <tr><td><input type=text ...></td><td>BB</td></tr>
>         </tbody>
>         </table>
>         <input type=button onclick="Klone()">
> 
> and JavaScript
> 
>         var Rose = document.getElementById("TB").rows
> 
>         function Klone() {
>           var node = Rose.item(Rose.length-1)
>           var newnode = node.cloneNode(true);
>           Rose.appendChild(newnode);

You cannot do that, Rose is a collection, 
you cannot appendChild() to a collection.

Chrome console will tell you this explicitly.

>           }
> 
> which, in Firefox, produces
> "TypeError: Rose.appendChild is not a function".
> 
>         It may help some if I remark that this line works :-
>                 Cel = Rose.item(Y).cells.item(X)
> 
> What should the code be, to work in current Firefox and other common
> browsers?

 function Klone() {
          var node = Rose.item(Rose.length-1);
          var newnode = node.cloneNode(true);
          node.parentNode.appendChild(newnode);
 };

You can test this with dirty outerHTML:

 function Klone() {
          var node = Rose.item(Rose.length-1);
          alert(node.parentNode.outerHTML);
          alert(node.outerHTML);
          var newnode = node.cloneNode(true);
          node.parentNode.appendChild(newnode);
          alert(node.parentNode.outerHTML);
 };

[not tested on Firefox, only on Chrome.]

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

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


Thread

Duplicating the last row of a Table Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-01-17 21:44 +0000
  Re: Duplicating the last row of a Table Zlatko Duric <zladuric@gmail.com> - 2014-01-18 01:52 +0100
    Re: Duplicating the last row of a Table Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-01-18 12:53 +0100
      Re: Duplicating the last row of a Table RobG <rgqld@iinet.net.au> - 2014-01-19 17:00 +1000
        Re: Duplicating the last row of a Table Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-01-19 14:41 +0100
  Re: Duplicating the last row of a Table "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-18 12:16 +0100
    Re: Duplicating the last row of a Table Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-01-19 17:00 +0000
  Re: Duplicating the last row of a Table Danny <dann90038@gmail.com> - 2014-01-18 11:32 -0800

csiph-web